Unable to configure Serial through Serial.begin properly


mak237

Recommended Posts

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?

Link to comment
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

Link to comment
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...

Link to comment
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

Link to comment
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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.