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

Setting baud rate, stop bits and parity for a MODBUS lib

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



Joined: 31 Dec 2005
Posts: 32

View user's profile Send private message

Setting baud rate, stop bits and parity for a MODBUS lib
PostPosted: Sat Dec 31, 2005 1:00 am     Reply with quote

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?
Guest








PostPosted: Tue Jan 03, 2006 1:29 pm     Reply with quote

I've never seen a function to chande stop bits and parity in realtime in CS, but it would be really great.
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