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 support@ccsinfo.com

Software uart baud rate change

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



Joined: 28 Jul 2005
Posts: 3

View user's profile Send private message

Software uart baud rate change
PostPosted: Fri Aug 19, 2005 8:18 am     Reply with quote

Hi, I had a problem, I'm working with two software uart and I would like to change the baud rate when I want doing a #use rs232 with a diferent baud rate but in the same stream that I allready had, but it doesn`t work and I don`t understand why.

#use rs232 (baud=9600, xmit=TX1, rcv=RX1, STREAM=COM_A, disable_ints) //PIC USART (AL PLC)
#use rs232 (baud=9600, xmit=TX2, rcv=RX2, STREAM=COM_B, disable_ints) //RS-232 maestro
#use rs232 (baud=9600, xmit=TX3, rcv=RX3, STREAM=COM_C, disable_ints) //RS-232 TTL al radio modem
#use rs232 (baud=9600, xmit=TX4, rcv=RX4, STREAM=COM_D, disable_ints) //RS-485


void uart_speed(char s, int puerto)
{
if(puerto==2)
{
if(s=='1')
{
delay_cycles(1);
#undef COM_B
#use rs232 (baud=19200, xmit=TX2, rcv=RX2, STREAM=COM_B, disable_ints
}

}
}

void main()
{
setting_uarts_speed(2);
enable_interrupts(INT_RB);
ext_int_edge(0,H_TO_L);
clear_interrupt(int_ext);
enable_interrupts(int_ext);
enable_interrupts(GLOBAL);
port_b_pullups(true);
while(mantente==0)
{

}

}
ALFA 705



Joined: 03 Jun 2005
Posts: 9

View user's profile Send private message

PostPosted: Sat Aug 20, 2005 5:53 am     Reply with quote

Hola,

Try to use: set_uart_speed (baud, [stream])

That's :
set_uart_speed(19200,COM_A);
set_uart_speed(9600,COM_B);
...

You can change uart speed on each "COM".
I hope this can help you.

Salud !
ALFA 705
Ttelmah
Guest







PostPosted: Sat Aug 20, 2005 6:53 am     Reply with quote

ALFA 705 wrote:
Hola,

Try to use: set_uart_speed (baud, [stream])

That's :
set_uart_speed(19200,COM_A);
set_uart_speed(9600,COM_B);
...

You can change uart speed on each "COM".
I hope this can help you.

Salud !
ALFA 705

No.
Look carefully at the manual entry. Note 'only applies to devices with the hardware UART' (should really say 'only applies to the hardware UART'...).
You cannot use 'set uart speed' on a software UART.
The problem is trying to be a bit 'too smart' in the original code. The USE RS232 command, creates the code for a software UART 'inline' when this is used. Unfortunately, this means you cannot switch 'on the fly'. Instead use something like this:

Code:

#use rs232 (baud=9600, xmit=TX2, rcv=RX2, STREAM=COM_B, disable_ints) //RS-232 maestro
#use rs232 (baud=19200, xmit=TX2, rcv=RX2, STREAM=COM_BFAST, disable_ints) //RS-232 maestro at 19200bps

#define 9600bps (0)
#define 19200bps (1)
int8 speed=9600bps;

#define soft_set_speed(rate) speed=rate

void putc_comb(char s) {
   switch (speed) {
   case 9600bps:
      fputc(COM_B,s);
      break;
   case 19200bps:
     fputc(COM_BFAST,s);
     break;
   //expand for more rates if needed
   }
}

soft_set_speed(9600bps);
printf(putc_comb,"Sent at 9600bps");
soft-set_speed(19200bps);
printf(putc_comb,"Sent at 19200bps");



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