Pages: [1]   Go Down
Author Topic: Set stop bits for Arduino Due using IDE 1.5.2  (Read 2127 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using a LCD that is connected to my Due using the RX1 pin. The LCD specifications state that while using the serial connection at 9600 baud that it takes 8 data bits and 2 stops bits with no parity. I am using IDE 1.5.2 to program my Due and based on my research I have found that I need to set this information using the Serial1.begin command. However, I have found 2 methods for setting data and neither one is accepted by the complier as valid.

Using:
Serial1.begin(9600, SERIAL_8N2);

Gives the error:
WireTester.ino: In function 'void setup()':
WireTester:18: error: 'SERIAL_8N2' was not declared in this scope

Using:
Serial1.begin(9600, 8, 2, N);

Gives the error:
WireTester.ino: In function 'void setup()':
WireTester:18: error: 'N' was not declared in this scope

What is the proper method for setting this information?
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 183
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you include <serial.h> at the top of your program?  That sets the #defines used like SERIAL_8N2
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't not include <serial.h>. I added it to the code and this came up:
fatal error: serial.h: No such file or directory compilation terminated.

There is no serial library included in the list of libraries from the 1.5.2 download. Is it located somewhere else?
Logged

Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Serial port configuration is currently not implemted on the Due (it was introduced on AVR boards just before the release of Due core).

I opened an issue to keep track of this:
https://github.com/arduino/Arduino/issues/1343
Logged

C.

Illinois, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guys,

Unfortunately the processor UART serial does not support anything other than 1 stop bit.
You'll have to change to one of the available USART ports which are full featured and support 1, 1.5 and 2 stop bits.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The SAM USART (I assume Serial1 is on a USART) does support 2 stop bits but you'll have to do the setup yourself by the sounds of it.

Write 2 into the NBSTOP field of the appropriate US_MR register. See section 36.8.2 of the data sheet.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Illinois, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, exactly as I mentioned above.

Here's how to do it assuming you'll be using Serial1:

   Serial1.begin(SERIAL_9600_BAUD);
   USART1->US_MR = US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_NO |
                US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL;


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For anyone else trying to get this to work on a Due the above is correct except if using Serial1 you should configure USART0 not USART1.

Code:
  Serial1.begin(9600);
  USART0->US_MR = US_MR_USART_MODE_NORMAL | US_MR_USCLKS_MCK | US_MR_CHRL_8_BIT | US_MR_PAR_NO |
                US_MR_NBSTOP_2_BIT | US_MR_CHMODE_NORMAL;

Would be very nice if the Serial.begin(speed, config) function was ported for the Due!
Logged

Pages: [1]   Go Up
Jump to: