max_evil
Newbie level 3
- Joined
- Jun 11, 2012
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,301
im trying to transfer bytes array from pic18f4550 to another one using usart and debug it using USB on one of them, the problem is that the reciver pic receives 2 bytes! on the first tx and then does not receive anything. im using the following code
--------
the compiler is C18 and 20Mhz clock with PLL. please advice !
Code:
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 131);
static unsigned char send_dummy[4];
static unsigned char recv_dummy[4];
int n_recv = 0;
int n_send = 0;
int send_bytes( unsigned char* bytes, int len)
{
int i = 0;
int n = 0;
for ( i = 0; i < len; i++)
{
while(BusyUSART());
WriteUSART( bytes[i] ); // send byte
DELAY_US_130
n++;
}
return n;
}
int recv_bytes( unsigned char *bytes, int len)
{
int i = 0;
int n = 0;
for ( i = 0; i < len; i++)
{
if ( DataRdyUSART() ) // is data aviliable in buffer?
{
bytes[i] = ReadUSART();
n++;
}else
{
// no data left return
return n;
}
}
return n;
}
// send load table
void send_lt(void)
{
/* test values */
send_dummy[0] = 0xD1;
send_dummy[1] = 0xD2;
send_dummy[2] = 0xD3;
send_dummy[3] = 0xD4;
n_send = send_bytes( send_dummy, sizeof(send_dummy));
}
void recv_lt(void)
{
memset( recv_dummy, 0, sizeof( recv_dummy));
n_recv = recv_bytes( recv_dummy, sizeof( recv_dummy));
....
}
Code:
the first main code
void main ()
{
while(1)
{
// check if we have something to read
if( DataRdyUSART() )
recv_lt();
send_lt();
}
}
the second main
void main()
{
send_lt();
recv_lt();
LED = ~(LED);
DELAY_MS_500
}
the compiler is C18 and 20Mhz clock with PLL. please advice !