John Morley
Joined: 09 Aug 2004 Posts: 97
|
|
Posted: Tue Sep 26, 2006 8:02 pm |
|
|
Hi All,
I finally had a chance to look at this problem again, and actually made some progress toward a resolution. To review, I'm trying to get two PIC's to communicate wirelessly using Aerocomm AC4490 modems. The transmitting PIC sends a string (example: #N00:04:00<CR>) and the receiving PIC receives the string. The receiving PIC uses an interrupt drive receive routine using INT_EXT and Pin B0 (the hardware UART is used for something else).
Code: |
#INT_EXT // Interrupt driven RS232 routine
void rs232_isr(void)
{
char temp; // local data storage
temp = fgetc(Aerocomm); // get rx data
output_toggle(Relay2_Out);
ISR_Loops++;
// If we got a '#', then the command is beginning.
if (temp == '#')
{
Serial_Index = 0;
RxBuffer[Serial_Index] = temp;
Serial_Index++;
return;
}
// If we got a CR, then the command is completed.
if (temp == CR)
{
RxBuffer[Serial_Index] = temp;
RX_Command_Ready = TRUE;
return;
}
// Save the character to the receive buffer.
RxBuffer[Serial_Index]=temp;
// Check for buffer overflow.
if ( Serial_Index >= (RX_SIZE - 1) )
Serial_Index = 0;
else
Serial_Index++;
}
|
The problem I was having is that the ISR appeared to be receiving all garbage characters. I then connected the two PICs together directly without the wireless modems (no software changes) and the code worked perfectly. Then I connected the receiving modem data output directly to a MAX232, and found that I was receiving the transmitted string 100%. These two facts appear to confirm that my software and the wireless link are fine! The only configuration that didn't work was when the wireless modem was connected directly to the PIC. I looked at the data output from the receive modem on a scope and found it was only swinging to 3.3V (the modem is a 3.3V part with 5V tolerant I/O). I added a two transistor buffer to the PIC input to boost the levels up to 5V but did not see any improvement in the garbage characters that were being received.
Finally, I started analyzing the data that was actually being received and noted that it was not random. In fact it was the same for each data transmission (the same transmission was being sent continuously). Next I added a counter increment inside my ISR and found that the ISR was being entered the same number of times (11) for each data transmission. Now, here is the strange part. Inside of Main, I wait for a flag that marks the receipt of a complete receive string. If this flag is true, I print the receive string.
Code: |
while(1)
{
// Here we have some serial data to process
if ( RX_Command_Ready == TRUE )
{
// Just to be safe, first things first...
disable_interrupts(GLOBAL);
RX_Command_Ready = FALSE;
fprintf(Console, "%s\n\r", RxBuffer);
// Serial command has been processed so we re-enable RS232
Serial_Index = 0;
enable_interrupts(GLOBAL);
}
|
The strange thing is that this code works fine when the PICs are directly connected, but prints garbage when they are connected using a wireless modem.
If I change the code to do this instead:
Code: |
while(1)
{
// Here we have some serial data to process
if ( RX_Command_Ready == TRUE )
{
// Just to be safe, first things first...
disable_interrupts(GLOBAL);
RX_Command_Ready = FALSE;
for (Loop_Index=0 ; Loop_Index<ISR_Loops ; Loop_Index++)
fprintf(Console, "%c\n\r", RXBuffer[Loop_Index]);
ISR_Loops = 0;
// Serial command has been processed so we re-enable RS232
Serial_Index = 0;
enable_interrupts(GLOBAL);
}
}
|
Each character is printed correctly even though the hardware configuration hasn't changed at all - when the wireless modems are connected!
So, what am I missing here? Printing the receive string at once using "%s" works for some hardware configurations and not others, and printing using "%c" is the only thing that seems to show me the proper receive characters when I'm using the wireless modems.
I admit this has me stumped. I did upgrade to the latest version of the compiler v3.249. _________________ John Morley |
|