Hi people. It's my first post here - hope the answer to my question would be helpful to all of you.
Here's the situation... I have an Arduino Nano v3 (ATmega328) and a serial device which requires communication to be exactly 19200 baud UART, Even parity, 1 stop bit, 1 start bit. The device is controlled by changing bit values in array of 20 bytes.
So far I'm unable to make it respond to the code I ported from a desktop application on C++
Here are parts of the code that as I believe should work:
void setup()
{
Serial.begin(19200, SERIAL_8E1);
}
As I understand after uploading the code to Nano and disconnecting it from a computer pins 0 and 1 should be Serial interface. So this code should confiure those pins to interface properly with the device. (And yes I've connected proper external power source, connected rx-tx accordingly)
void sendMessage()
{
uint8_t *buff = new uint8_t[20];
buff[0] = 0xB0;
buff[1] = 0x3B;
buff[2] = 0x55;
buff[3] = 0x60;
buff[4] = 0x00;
...
buff[18] = 0x00;
//checksum
uint8_t cs = 0;
for(int i=0;i<19;++i)
cs += buff[i];
buff[19] = cs;
Serial.write(buff, 20);
//clears
delete []buff;
buff = NULL;
}
Structure is simple - first three bytes are headers, last is checksum others are various parameters. This is what worked perfectly on desktop. Well not exactly - there I used GCC compiler that understood 0b01101010 or used std::bitset. But I suppose that Arduino's compiler is ok with HEX so what is written should be ok as well... But as you may guess it isn't - I get 0 response.
So I will be very thankful if you could shed some light on the matter: maybe it is advised to use bitset struct and unions to write byte arrays into serial device?
Thanks in advance!