![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ntgcp_08
Joined: 21 Feb 2008 Posts: 24
|
RS232 with 2 stop bits |
Posted: Thu Feb 21, 2008 1:28 pm |
|
|
Why does the following code generate 4 stop bits? On my oscilloscope I can verify that after my 8th bit is sent, the TX line is idle for approximately 420uS before the next start bit is sent. I was expecting the idle time to be around 200uS.
Code: |
#use rs232(baud=9600,parity=N,xmit=SATGSM_TX,rcv=SATGSM_RX,bits=8,restart_wdt,STREAM=SATGSM232,ERRORS,STOP=2)
|
If I remove the 'STOP=2' from the above statement, my stop bit is only 100uS long which is the correct time for 1 stop bit. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 2:17 pm |
|
|
Post:
1. Your PIC.
2. Your compiler version.
3. The actual CCS pin numbers used for xmit and rcv.
4. Your oscillator frequency. |
|
![](templates/subSilver/images/spacer.gif) |
ntgcp_08
Joined: 21 Feb 2008 Posts: 24
|
|
Posted: Thu Feb 21, 2008 2:27 pm |
|
|
I'm using the PIC18F6722
PCWH V4.066
xmit pin is pin G1
rcv pin is pin G2
oscillator freq is 4Mhz |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 2:35 pm |
|
|
Also post the code that you use to transmit the bytes. Preferably, post a
complete (but short) little test program that demonstrates the problem.
If you do that, I can attempt to duplicate the problem. |
|
![](templates/subSilver/images/spacer.gif) |
ntgcp_08
Joined: 21 Feb 2008 Posts: 24
|
|
Posted: Thu Feb 21, 2008 4:25 pm |
|
|
Code: |
char buffer[5];
int indx;
int main()
{
disable_interrupts(GLOBAL);
buffer[0] = "w";
buffer[1] = "o";
buffer[2] = "r";
buffer[3] = "k";
buffer[4] = "!";
while(1){
for(indx = 0; indx<5; indx++)
fputc(buffer[indx], SATGSM232);
delay_ms(3000);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 5:15 pm |
|
|
To test the number of stop bits, I would use 0xAA for the test characters.
Then a typical transmisstion would be:
The first 0 is the start bit, then you have the 0xAA data, and finally the
two 11's are the stop bits.
Can you change your data to the following, and then re-test it ?
Code: |
buffer[0] = 0xAA;
buffer[1] = 0xAA;
buffer[2] = 0xAA;
buffer[3] = 0xAA;
buffer[4] = 0xAA; |
|
|
![](templates/subSilver/images/spacer.gif) |
ntgcp_08
Joined: 21 Feb 2008 Posts: 24
|
|
Posted: Thu Feb 21, 2008 6:01 pm |
|
|
Since the LSB is transmitted first, I change the test characters to 0x55 so my transmission should be
I first tested with two stop bits Code: | #use rs232(baud=9600,parity=N,xmit=SATGSM_TX,rcv=SATGSM_RX,bits=8,restart_wdt,STREAM=SATGSM232,ERRORS,STOP=2) |
and I saw 4 stop bits on the oscilloscope
I then tested with three stop bits Code: | #use rs232(baud=9600,parity=N,xmit=SATGSM_TX,rcv=SATGSM_RX,bits=8,restart_wdt,STREAM=SATGSM232,ERRORS,STOP=3) |
and I saw 5 stop bits on the oscilloscope
I then tested with four stop bits Code: | #use rs232(baud=9600,parity=N,xmit=SATGSM_TX,rcv=SATGSM_RX,bits=8,restart_wdt,STREAM=SATGSM232,ERRORS,STOP=4) |
and I saw 6 stop bits on the oscilloscope
Finally I tested with one stop bit both with the 'stop = 1' and without it... Code: | #use rs232(baud=9600,parity=N,xmit=SATGSM_TX,rcv=SATGSM_RX,bits=8,restart_wdt,STREAM=SATGSM232,ERRORS,STOP=1) | and Code: | #use rs232(baud=9600,parity=N,xmit=SATGSM_TX,rcv=SATGSM_RX,bits=8,restart_wdt,STREAM=SATGSM232,ERRORS) |
each time I saw on the correct output on the oscilloscope |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 21, 2008 7:52 pm |
|
|
You're right about the LSB first.
Here's the .LST file code for the transmission. It shows a software
delay of two bit periods.
Code: |
// Wait in a loop until TX2REG is empty.
00004: BTFSS PIR3.TX2IF
00006: BRA 0004
// Wait in a loop until the byte is transmitted.
00008: MOVFF 0D,TXREG2
0000C: BTFSS TXSTA2.TRMT
0000E: BRA 000C
// Do a software delay loop for 208us.
// This is two bits, at 104us per bit
00010: MOVLW 45 // 69 decimal
00012: MOVWF @00
00014: DECFSZ @00,F
00016: BRA 0014
00018: GOTO 009E (RETURN) |
I don't have an 18F6722, so I tested your code with an 18F452,
with vs. 4.066 and two stop bits. Using the delta time cursors on
the scope, I measure 307us of high level time between two bytes.
This is the time between where the MSB bit ends, and the start bit
of the next byte begins. One bit time is 104 us. I'm curious as to
what you see. Make sure the Time/Div knob is not set in the
"variable" mode. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|