stolzie
New Member
Hi All
I have a project that uses two RS232 interfaces. One uses the EUSART module and the other is software. While running in debug using an ICD2, the code works perfectly. But when I program the PIC for release, there's a weird timing issue that screws up the RS232 data.
I'm using a PIC18F6622. MPLAB IDE v8.50. And an ICD2.
Code for the hardware Interface:
Code for the the software Interface:
The results that I'm getting under release is if I send (say) an ASCII Char '1' (0x31), I recieve a mix of the '1' and '9' (0x39) and the occasional random character. If I send an 'A' (0x41), I get a mix of 'A', 'a' (0x61) and 'y' (0x79) and occasional randoms.
So it seems as if some voodoo gremlin is delaying the controller while its forming the RS232 waveform. And I'm getting (pretty much) the same result with both the EUSART and the software interface. And it works flawlessly in debug. I've even programmed the PIC using a PM3 with the same result.
Can anyone shed some light on what this might be.
Thanks in advance.
Stolzie
I have a project that uses two RS232 interfaces. One uses the EUSART module and the other is software. While running in debug using an ICD2, the code works perfectly. But when I program the PIC for release, there's a weird timing issue that screws up the RS232 data.
I'm using a PIC18F6622. MPLAB IDE v8.50. And an ICD2.
Code for the hardware Interface:
Code:
void rs232PutA(BYTE output)
{
INTCON_GIEH = 0; // Putting this in didn't change the result
while (!PIR3bits.TX2IF);
TXREG2 = output;
INTCON_GIEH = 1;
}
Code for the the software Interface:
Code:
void rs232PutB(BYTE output)
{
unsigned char bitCounter;
int waitCount;
// Disable Timer Interrupt
INTCON_TMR0IE = 0;
INTCON_GIEH = 0; // Putting this in didn't change the result
switch (AppConfig.PortB.RS232_Baud)
{
case 0 : waitCount = WAIT_PERIOD_2400; break;
case 1 : waitCount = WAIT_PERIOD_4800; break;
case 2 : waitCount = WAIT_PERIOD_9600; break;
case 3 : waitCount = WAIT_PERIOD_19200; break;
case 4 : waitCount = WAIT_PERIOD_38400; break;
case 5 : waitCount = WAIT_PERIOD_57600; break;
case 6 : waitCount = WAIT_PERIOD_115200; break;
}
// Send Start bit
Tx_B = 0;
rs232Wait(waitCount);
// Send data bits
bitCounter = AppConfig.PortB.RS232_Bits;
do
{
if (output & 0x01)
Tx_B = 1;
else
Tx_B = 0;
output >>= 1;
rs232Wait(waitCount);
bitCounter--;
} while (bitCounter);
// Send Stop bit
Tx_B = 1;
rs232Wait(waitCount * AppConfig.PortB.RS232_StopBits / 2);
INTCON_TMR0IE = 1;
INTCON_GIEH = 1;
}
void rs232Wait(int waitPeriod)
{
do
{
Nop();
waitPeriod--;
} while (waitPeriod);
}
The results that I'm getting under release is if I send (say) an ASCII Char '1' (0x31), I recieve a mix of the '1' and '9' (0x39) and the occasional random character. If I send an 'A' (0x41), I get a mix of 'A', 'a' (0x61) and 'y' (0x79) and occasional randoms.
So it seems as if some voodoo gremlin is delaying the controller while its forming the RS232 waveform. And I'm getting (pretty much) the same result with both the EUSART and the software interface. And it works flawlessly in debug. I've even programmed the PIC using a PM3 with the same result.
Can anyone shed some light on what this might be.
Thanks in advance.
Stolzie