grindylow
Newbie level 6
hello, I have been playing around with 18F4550 as a USB device using a modified CDC firmware. I recently needed to have another 18F4550 to be controlled as a slave device. The problem is whenever I send data to the slave, the master hangs up(the blinkusb status freezes). I interfaced it using USART then changed it to software UART then I2C and the same scenario goes on. Prior to this, I successfully managed to interface a sensor that outputs serial data, I did that using software UART(just Rx is used). Now I interfaced it using SPI and it doesn't freezes anymore but the slave still doesn't get any data. Can anyone give me a hand on this? I'm really stuck on this..
here is my master code, and it's within the ProcessIO() function:
here is my slave code:
both pics are 18F4550 running at 48MHz
here is my master code, and it's within the ProcessIO() function:
Code:
if (getsUSBUSART(USB_Out_Buffer, 4))
{
received_data0 = USB_Out_Buffer[0];
received_data1 = USB_Out_Buffer[1];
switch(received_data0)
{
case 'T' :
USB_In_Buffer[0] = 'X';
if (mUSBUSARTIsTxTrfReady())
{
putUSBUSART(USB_In_Buffer,1);
}
break;
case 'q' :
mLED_3_Off();
break;
case 'Q' :
mLED_3_On();
break;
case 'w' :
mLED_4_Off();
break;
case 'W' :
mLED_4_On();
break;
case '*' :
servo='a';
break;
default : break;
}
}
if(servo=='a')
{
OpenSPI(SPI_FOSC_4, MODE_11, SMPMID);
PORTCbits.RC2=0;
Delay10TCYx(5);
WriteSPI(received_data1);
Delay10TCYx(5);
PORTCbits.RC2=1;
CloseSPI();
servo=0x00;
}
here is my slave code:
Code:
void main(void)
{
char master;
int addr, i;
TRISDbits.TRISD0=0;
LED=0;
for(i=0;i<18;i++) {
Delay10KTCYx(0);
}
for(i=0;i<7;i++) {
Delay1KTCYx(0);
}
for(i=0;i<5;i++) {
Delay100TCYx(0);
}
while(1)
{
LED=1;
OpenSPI(SLV_SSON, MODE_11, SMPMID);
if(DataRdySPI())
master = ReadSPI();
CloseSPI();
switch(master)
{
case '1':
LED=0;
for(i=0;i<18;i++) {
Delay10KTCYx(0);
}
for(i=0;i<7;i++) {
Delay1KTCYx(0);
}
for(i=0;i<5;i++) {
Delay100TCYx(0);
}
break;
case '2':
LED=1;
for(i=0;i<18;i++) {
Delay10KTCYx(0);
}
for(i=0;i<7;i++) {
Delay1KTCYx(0);
}
for(i=0;i<5;i++) {
Delay100TCYx(0);
}
break;
default: break;
}
}
}
both pics are 18F4550 running at 48MHz