I am using Arduino Uno to send serial data to another device which requires the data to be in below format :
1 Start Bit (always HIGH)
8 Data Bit (LSB bit sent first)
1 Parity Bit (Even Parity)
1 Stop Bit (always HIGH)
Arduino Uno has only 1 set of serial channel (Pin 0 for Rx, 1 for Tx). As, I need to transmit/receive data and also see some output in the serial display simultaneously, I cannot use the pins 0 and 1 for serial communication. So the only choice which I have now is to use software serial channel for serial communication. Now when I create software serial channel and try to initialize the baud rate along with the parity/stop bits, I get error message “no matching function for call to ‘SoftwareSerial::begin(int, int)’”
So I understand that the Software serial ports can be configured only for baud rate but not for Start/Parity/Stop bits.
Probably based on the desired baud rate, I can calculate the time required to transmit one bit and use it to send the data bit by bit. But I assume that there should exist some other alternatives which is better than sending data bit by bit.
If anyone is aware of such issue and how it can be handled properly, could you please let me know so that I can proceed further.
SERIAL_8N2 = 1 start, 2 stop, no parity, eight bits, for instance, so you might want SERIAL_8E1
Start bit is always SPACE, which is always LOW on Arduino Uno hardware:
MSB is sent last in serial, always - so you are not talking about standard serial at all... I think
you may be able to do this with SoftwareSerial, otherwise it will need bit-bashing.
As far as I can see from the Reference material you cannot set config parameters with SoftwareSerial but you can with HardwareSerial - including SERIAL_8E1 and SERIAL_8O1
MSB is sent last in serial, always - so you are not talking about standard serial at all... I think
you may be able to do this with SoftwareSerial, otherwise it will need bit-bashing.
It is EVEN parity.
Both start bit and stop bit is expected to be HIGH.
LSB bit is sent first. I mentioned it wrongly as MSB bit first. I have updated my question accordingly.
If I need to implement my serial communication with bit-bashing approach, what all precautions do I need to take care of ? It would also help if you could brief me the basic flow of execution for bit-bashing approach for both transmission and reception of serial data.
Both start bit and stop bit is expected to be HIGH.
How does the device know when the message starts? If a 1 is transmitted as HIGH and you send the data byte 0xFF, the entire transmission will be 11111111111 - I don't see how it can determine where the message starts, especially if you transmit a long sequence of 0xFF.
Standard RS232 asynchronous transmissions have the line in a logical MARK state (usually HIGH) when idle and the start bit is always a zero (SPACE) which allows the other end to detect the start of the transmission.
el_supremo:
What is the device you are sending to?How does the device know when the message starts? If a 1 is transmitted as HIGH and you send the data byte 0xFF, the entire transmission will be 11111111111 - I don't see how it can determine where the message starts, especially if you transmit a long sequence of 0xFF.
Standard RS232 asynchronous transmissions have the line in a logical MARK state (usually HIGH) when idle and the start bit is always a zero (SPACE) which allows the other end to detect the start of the transmission.
Pete
The device is an energy meter which has various electrical parameters stored within the "holding Registers" (Modbus RTU). The meter has RS485 channel to interface with external devices. To get the data from holding register to Arduino, I wanted to establish serial connection with data bit-format mentioned earlier.
While sending serial data (modbus query message) to the meter, I should wait for 3.5 character time to mark the beginning of data frame before proceeding with data transmission.