mak237

Unable to configure Serial through Serial.begin properly

9 posts in this topic

For my ongoing project I am trying to interface the Papilio with a Roboteq AX2550 motor controller. The default serial configuration on the arduino and by extension the ZAP IDE is 8 data bits, no parity, and one stop bit. The motor controller can not use this as explained in the excerpt from the manual below:

 

The AX2550 serial communication port is set as follows:

 

9600 bits/s, 7-bit data, 1 Start bit, 1 Stop bit, Even Parity

 

Communication is done without flow control, meaning that the controller is always ready to receive data and can send data at any time.

 

These settings cannot be changed. You must therefore adapt the communication setting in your PC or microcomputer to match those of the controller.

 

In the Arduino documentation of Serial.begin() it outlines a way to change this by using the format Serial.begin(speed, config) for a command.

http://arduino.cc/en/Serial/Begin

 

When I try to enter the appropriate command in the ZAP IDE, Serial.begin(9600, SERIAL_7E1), I get an error stating that 'SERIAL_7E1' undeclared (first use this function).  After searching for this error I found a few of references to this problem about a year ago on the arduino forums and people claiming that it worked as of arduino 1.0.4.

 

All of this leads me to the question, is there any easy way to change this with the ZAP IDE? If not, what would I have to do to work around this problem? Is this not possible using the UART in the papilio schematic library?

Share this post


Link to post
Share on other sites

The current UART implementation only does 8N1.

 

I can provide you a custom implementation for other, if you need. But you can always generate (as Magnus said) the parity bit yourself.

 

Alvie

Share this post


Link to post
Share on other sites

Ah, that's good to know. I didn't know if it was something as simple as a bug or configuration problem, or if it was an actual compatability issue.  It's

 

How much time would it take for a custom implementation? I don't want to take too much of your time if it can be done more easily some other way.

 

Anyway, it probably would be best having a custom implementation since I'm trying to leave as much of the messy code out of the soft processor as possible to make it easier for people that work with me on the project to read through and understand the code.

 

Mak237

Share this post


Link to post
Share on other sites

Doing a custom UART is a lot of work.

 

Off the top of my head this should be enough C to generate parity for 'a' and set it. It would pay to test it as I haven't even compiled it!

 

char addParity(char a){  unsigned char p;  p = a;  p ^= (p >> 4);  p ^= (p >> 2);  p ^= (p >> 1);  a |= (p<<7);  return a;}

 

and you should then be able to do something like "Serial.write(addParity('h'));", as long as it works as I think it should...

Share this post


Link to post
Share on other sites

I'll try that when I get back into the lab on Monday then. Hopefully that's all I need to do to be able to communicate with this motor controller.

 

Thanks for all of the help with this, I really appreciate it.

Share this post


Link to post
Share on other sites

For a byte you can do this and you don't need the later shifts

 

p ^= (p>>4);

parity = (0x6996 >> p) & 1;

 

(ie its a fold and a 16 way lookup table)

 

Alan

(lookup hack c/o Mathew Hendry)

Share this post


Link to post
Share on other sites

Doing a custom UART is not that much of hard work. What takes time is to adjust the C++ API to deal with that, and to properly distinguish between all of UART versions.

 

If you wish to do the C++ API adjustments, I can provide you an HDL version to support 8N1, 7E1 and 7O1. You just need to fiddle with two additional configuration bits.

 

Alvie

Share this post


Link to post
Share on other sites

I tried the code hamster suggested and it seems to be working. The serial settings on the scope in the lab saw everything I sent to it as having 7 bits with even parity instead of the normal 8 bits with no parity. The only thing left to do is testing it out with the motor controller. Thanks for all the help and suggestions!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now