dmendesf
Joined: 31 Dec 2005 Posts: 32
|
Setting baud rate, stop bits and parity for a MODBUS lib |
Posted: Sat Dec 31, 2005 1:00 am |
|
|
Hi, i�m porting a MODBUS library (master and slave implementation, very memory efficient, callback functions for the slave part, very well designed to follow the standards...) to the CCS compiler. The only part missing is a function to set baud rate, stop bits and parity (in execution time). So i�ve tried this:
Code: |
signed int set_mod_uart(unsigned long int baud, par_type parity, int stopbits)
{
disable_modbus();
g_parity = parity;
g_baud = baud;
switch(parity)
{
case O:
if(stopbits == 1)
{
#use rs232(baud=9600,parity=O,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS,stream=MODBUS)
}
else return -1;
break;
case E:
if(stopbits == 1)
{
#use rs232(baud=9600,parity=E,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS,stream=MODBUS)
}
else return -1;
break;
case N:
if(stopbits == 1)
{
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS,stream=MODBUS)
}
else if(stopbits == 2)
{
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS,stream=MODBUS)
TXSTA |= 0x41;
}
else return -1;
break;
}
switch(baud)
{
#if CCLOCK < 9497000
case 1200:
set_uart_speed(1200);
break;
#endif
case 2400:
set_uart_speed(2400);
break;
case 4800:
set_uart_speed(4800);
break;
case 9600:
set_uart_speed(9600);
break;
case 19200:
set_uart_speed(19200);
break;
case 38400:
set_uart_speed(38400);
break;
case 57600:
set_uart_speed(57600);
break;
case 115200:
set_uart_speed(115200);
break;
default:
return -1;
}
calc_t35(baud);
return 0;
}
|
Ignore for now the calls to "calc_t35()" and "disable_modbus()". I just can�t make this function work. With parity it never works, without parity it sometimes works, sometimes don�t. It gaves really strange results. I�m using 3.236. Any ideas? |
|