CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Change Baud and Parity on-the-fly

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

Change Baud and Parity on-the-fly
PostPosted: Tue Apr 26, 2005 7:56 am     Reply with quote

I am rehashing this from another post..

I want to Receive at 300,o,8,1. I want to transmit at 9600,n,8,1.

The chip is 18F452 and I want to use the hardware UART.

If I comment out the set_uart_speed(); lines, the device will transmit at 300 baud no parity so resetting the parity bit for transmit works. It seems changing to 9600 baud and then turning off parity is not working.

Code:
 

//abbreviated code....
#use rs232(baud=300,parity=O,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

#int_RDA
RDA_isr(){
//receive 300 odd parity here

}

main(){

//do stuff....

//if I need to transmit data....
      if (txresp){
         disable_interrupts(INT_RDA);
         set_uart_speed(9600);
         #asm
         BCF    0xFAC.6  // clears the 9 bit transmit enable bit
         #endasm
         txresp = 0;
         putc('@');
         putc('h');
         putc('i');
         set_uart_speed(300);
         enable_interrupts(INT_RDA);
      }


}



Here is the listing....
You can see 66 gets moved into FAC then I reset bit 6 of FAC to turn off parity transmission.

Code:

....................       if (txresp){
523C:  MOVF   x7B,F
523E:  BZ    5296
....................          disable_interrupts(INT_RDA);
5240:  BCF    F9D.5
....................          putc(0);
5242:  MOVLB  2
5244:  CLRF   x37
5246:  MOVLB  0
5248:  CALL   3FFA
....................          set_uart_speed(9600);
524C:  MOVLW  1A
524E:  MOVWF  FAF
5250:  MOVLW  66
5252:  MOVWF  FAC
....................          #asm
....................          BCF    0xFAC.6
5254:  BCF    FAC.6
....................          #endasm
....................          txresp = 0;
5256:  MOVLB  1
5258:  CLRF   x7B
....................          putc('@');//0x80);
525A:  MOVLW  40
525C:  MOVLB  2
525E:  MOVWF  x37
5260:  MOVLB  0
5262:  CALL   3FFA
....................          putc('h');//remoteid);
5266:  MOVLW  68
5268:  MOVLB  2
526A:  MOVWF  x37
526C:  MOVLB  0
526E:  CALL   3FFA
....................          putc('i');//~remoteid);
5272:  MOVLW  69
5274:  MOVLB  2
5276:  MOVWF  x37
5278:  MOVLB  0
527A:  CALL   3FFA
....................          putc(' ');//func);
527E:  MOVLW  20
5280:  MOVLB  2
5282:  MOVWF  x37
5284:  MOVLB  0
5286:  CALL   3FFA
....................          set_uart_speed(300);
528A:  MOVLW  D4
528C:  MOVWF  FAF
528E:  MOVLW  62
5290:  MOVWF  FAC
....................          enable_interrupts(INT_RDA);
5292:  BSF    F9D.5
5294:  MOVLB  1

3FFA:  MOVLW  08
3FFC:  MOVWF  01
3FFE:  MOVLB  2
4000:  CLRF   x38
4002:  INCF   x38,F
4004:  MOVFF  237,00
4008:  MOVF   00,W
400A:  XORWF  x38,F
400C:  RRCF   00,F
400E:  DECFSZ 01,F
4010:  BRA    4008
4012:  BTFSS  F9E.4
4014:  BRA    4012
4016:  MOVLW  FE
4018:  ANDWF  FAC,F
401A:  BTFSC  x38.0
401C:  BSF    FAC.0
401E:  MOVFF  237,FAD
4022:  MOVLB  0
4024:  RETLW  00


ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Tue Apr 26, 2005 8:13 am     Reply with quote

I added 10ms delays between the putc lines and it worked. The program must not be waiting for the TSR to empty before sending the next character and I must have been overrunning the buffer???
Ttelmah
Guest







PostPosted: Tue Apr 26, 2005 9:17 am     Reply with quote

The program does wait for the buffer to empty before adding another character, but there will still be characters 'in transit', after the last putc. You need to wait long enough for the character in the output shift register to send, and then the one in the transmitter buffer to move into the shift register, between the last putc, and changing the baud rate. By delaying between each character, you are ensuring that the last character, has actually transferred to the shift register, and the way the UART is meant to work, is that it won't change speeds, until a character 'in transit' in this register, has completed (some chips are faulty in this regard...), hence it then works.
If you just add a test after the last putc, for the transmitter buffer empty flag being set, before you change the rate, it should work.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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