I am using a BL2600 Single-board computer and am having trouble with the RS-485.
I have a simple program that uses RS-485 to send a command to another device (just transmitting, no receiving on this side). However, when I run it, it sends the data too fast, despite me setting the baud rate. I have to add 1 ms delays between the bytes to actually keep them separate. Here is my code:
#class auto
#define EINBUFSIZE 255
#define EOUTBUFSIZE 255
nodebug //??
void msDelay(unsigned int delay)
{
auto unsigned long done_time;
done_time = MS_TIMER + delay;
while( (long) (MS_TIMER - done_time) < 0 );
}
void main()
{
char highb, lowb;
brdInit();
serEopen(38400);
serEwrFlush();
serErdFlush();
serMode(1);
for(;;)
{
//G2P60
if(!digIn(0))
{
highb=0x13;
lowb=0x88;
}
else if(!digIn(1))
{
highb=0x27;
lowb=0x10;
}
else if(!digIn(2))
{
highb=0x3A;
lowb=0x98;
}
else if(!digIn(3))
{
highb=0x4E;
lowb=0x20;
}
else
{
highb=0;
lowb=0;
}
ser485Tx();
serEputc(0x00);
msDelay(1);
serEputc(0x02);
msDelay(1);
serEputc(60);
msDelay(1);
serEputc(highb);
msDelay(1);
serEputc(lowb);
msDelay(1);
ser485Rx();
}
}
Without those "msDelay(1); " statements there, the bytes are not recognized as separate when I look at the output via Tera Term. Since I set the baud rate, and put these int Serial port E’s buffer, I assumed the buffer’s data would be sent at the correct baud rate with sufficient time between each byte, but I am apparently mistaken.
Am I missing something on how I am supposed to queue up commands to be sent on RS-485?