Pages: [1]   Go Down
Author Topic: Arduino IDE 1.0.x - direct UART register manipulation stopped working  (Read 1921 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I understand that the IDE has now moved away from allowing direct UART manipulation in place of Serial3.begin(speed, config) etc

I have some code which requires UART3 on a Mega 2560 to be changed to 8E1 (even parity)
The following code stopped working

Code:
UCSR3C = ( UCSR3C & ~_BV(UPM00) | _BV(UPM01) );

I have since tried to use 
Code:
Serial3.begin(9600, SERIAL_8E1);
However this doesn't work. Checking my inline scanner it seems to still be using 8N1.

I'm current force to compile on an earlier IDE to get it to work.

Any insight is greatly appreciated.

Thanks in advance.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13012
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


http://arduino.cc/forum/index.php/topic,97455.0.html
... #6, fifth bullet.
Logged

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


Thanks for your reply .. but it doesn't help much smiley

Ill ask my question a different way. Has something been done / left / still to do with
A: Direct UART register maniplation such as the code I posted above
B: Has anyone got the new SerialX.begin(SPEED, SERIAL_XXX) to work correctly.

In my testing using an in-line external scanner my Arduino Mega 2560 is still transmitting 8N1 .. not 8E1 which I have been directing it to do (again see above code posted)

Thanks in advance
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2565
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did not even notice you could now use a second parameter in Serial.begin to specify the protocol. What version introduced this? The reference pages for Serial.begin in the 1.0.3 download do not refer to the extra protocol parameter but the on-line version does.

I do not have a Mega but after reading this thread and referring to the on-line documentation I can confirm the protocol parameter is working on a v2 UNO using 1.0.3 IDE. Below is the output. CH1 = 8N1, CH2 = 8O1 & CH3 = 8E1


* Serial.png (47.91 KB, 1025x871 - viewed 60 times.)
« Last Edit: December 18, 2012, 07:54:42 am by Riva » Logged


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

Cheers for posting that up ... very interesting.

Quick off topic question ... what software / hardware are you using for your screenshot ?

I have been compiling with 1.0.2 .. Ill try 1.0.3 to see if I can get it running.

Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2565
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quick off topic question ... what software / hardware are you using for your screenshot ?
I am using this little device http://www.ikalogic.com/ikalogic-products/scanalogic-2/

Quote
I have been compiling with 1.0.2 .. Ill try 1.0.3 to see if I can get it running.
As I said I don't have a Mega so could not test it on the other serial ports but would assume (foolishly) they all work the same.


Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19015
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I understand that the IDE has now moved away from allowing direct UART manipulation in place of Serial3.begin(speed, config) etc

Where was that announced?

Logged


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

I understand that the IDE has now moved away from allowing direct UART manipulation in place of Serial3.begin(speed, config) etc

Where was that announced?



It wasn't but after testing this still doesnt work.

Unfortunately neather does using the Serial3.begin(9600, SERIAL_8E1); command.
It doesnt actually transmit or recieve in 8E1 mode .. its still in 8N1.
I have tried this again in Arduino IDE 1.0.5 for Windows.
The last time it worked was in an old 023 version which is what i'm still having to use to get my program to work.

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19015
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please post a sketch that demonstrates this, not a single line.
Logged


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

Code:
void setup() {

Serial.begin(115200);  // Serial Monitor
Serial1.begin(115200);  // Display
Serial3.begin(9600);   // Device Comms

// ******************* Ardiuno Mega 2560 ***********************************************************
UCSR3C = ( UCSR3C & ~_BV(UPM00) | _BV(UPM01) ); // Arduino Mega 2560 even parity set
  }

The above works in IDE 023, however the UCSR3C commands (direct register manipulation) compiles however doesnt change the internal registers any more (hence the 'its not supported comment) ... Im not worried about it being removed or disabled .. but as you will see below the replacement just doesn't work any more. There is nothing in my code that is fancy. Infact I have gone back to basics and run the same tests with example comms code with the same results.

Quote
Code:
void setup() {

Serial.begin(115200);  // Serial Monitor
Serial1.begin(115200);  // Display
Serial3.begin(9600, SERIAL_8E1);   // Device Comms

// ******************* Ardiuno Mega 2560 ***********************************************************
//UCSR3C = ( UCSR3C & ~_BV(UPM00) | _BV(UPM01) ); // Arduino Mega 2560 even parity set
  }

The above doesn't work in Ardiuno IDE 1.0.1,2,4 or 5.

My device receiving a command and all other low level logic tests confirm that the logic level is still being transmitted at 8N1.


Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19015
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When I asked for a sketch that demonstrates it, I meant one that compiles. Anyway, here is my test based on yours:

Code:
void setup()
  {
  Serial3.begin(9600, SERIAL_8E1);   // Device Comms
  }  // end of setup

void loop ()
  {
  Serial3.print ("abcdefghijklmnopqrstuvwxyz");
  delay (500); 
  }  // end of loop

It works, so your measurement must be in error:



The parity bit is arrowed. As you can see it is high when needed to make the total number of 1 bits even.

IDE 1.0.5.
Logged


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

Thanks for your reply Nick and testing.

Interesting, I will keep trying this end and update the thread when I can.


Cheers.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 135
Posts: 6782
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
UCSR3C = ( UCSR3C & ~_BV(UPM00) | _BV(UPM01) ); // Arduino Mega 2560 even parity set
I can't think of any reason that this would stop working in 1.0.x, either.  Although I'd certainly have used at least one more set of parens...  The AVR Microcontroller has no protection of anything, nor does the arduino environment.  It *can't* stop you from re-writing the config register.
Logged

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

Ok so after running a new logic analysis tool I did a whole bunch of before and afters.

IDE 023
IDE 1.5 with direct register manipulation for 8E1
IDE 1.5 with Serial.begin(9600, SERIAL_8N1)
IDE 1.5 with Serial.begin(9600, SERIAL_8E1)

And it all tested good... accept I noticed one little difference between IDE 023 and IDE 1.5

I was using the serial.print command which in 023 output true bytes. In IDE 1.5 it outputs ASCII smiley
Changed to serial.write and it fixed the issue smiley

Only probably I have now is that the performance of the SDCard library i'm using has gone from about 8-7 times a second down to 3-4 times a second which is  far too slow for my needs. Even after some tweaks, its just very slow.

Ill try mucking around with formatting of the cards.


Thanks all that pitched in to help solve this.
Logged

Pages: [1]   Go Up
Jump to: