chipKIT® Development Platform

Inspired by Arduino™

chipKIT Max32 - Serial communication problem

Created Mon, 10 Jun 2013 20:22:32 +0000 by josenuno


josenuno

Mon, 10 Jun 2013 20:22:32 +0000

Hello,

I am currently working on a project in my university which involves the UART of a chipKIT Max32. I need to send some commands to a driver using TX0, but the value sent by TX0 is not the one I sent using Serial.print() or Serial.write(). In order to understand such issue I used a scope and the following code to send and check some values.

void setup() { Serial.begin(9600); }

void loop() { int aux = 3; //Example: 3 is to be sent through TX0. //char aux;

Serial.write(aux); //Serial.print(aux); delay(300); }

With or without the delay, the value sent by TX0 is still not the right one. Values from 0 to 9 were tested and the results are presented in the tables below (the output values should be compared to the ones in the ASCII table).

Using the command Serial.write(): input (DEC) output input (DEC) output 0 FF '0' F6 1 7F '1' 67 2 B7 '2' B3 3 7E '3' 66 4 DF '4' D9 5 7D '5' 65 6 BE '6' B2 7 7C '7' 64 8 EF '8' EC 9 7B '9' 63

Using the command Serial.print(): input (DEC) output input (DEC) output 0 F6 '0' F6 1 67 '1' 67 2 B3 '2' B3 3 66 '3' 66 4 D9 '4' D9 5 65 '5' 65 6 B2 '6' B2 7 64 '7' 64 8 EC '8' EC 9 63 '9' 63

It can be seen that there is a pattern for the odd numbers, even when I try to send values with 2 digits (for example aux=71). But the problem is that I have pre-defined values (odd and even numbers and letters) to send to a driver.

I also sent letters using Serial.print() and the results did not match the right ones in the ASCII table. For example, with Serial.print('A') we see in the scope 5F (hex), while ASCII table shows that A corresponds to 41 (hex). The attached figure shows a snapshot taken from the scope for this case.

Does anyone have any ideas about what causes such problem and/or how to solve it?

Thank you, Jose


george4657

Tue, 11 Jun 2013 03:44:13 +0000

This one had me scratching my head. I got the same results on Serial and on Serial1 (pins 19 RX1)

'A' Binary = 01000001 41 Hex add start bit = 101000001 add stop bit = 1010000010 repeat = 1010000010101000001010100000101010000010 repeat = 1_1_____1_1_1_____1_1_1_____1_1_1_____1_

This is the pattern you see. If you are going to hook up an external rs232 you should use Serial1 2 or 3 as Serial is hooked to the FTDI chip for USB programming.

George


mikes

Tue, 11 Jun 2013 15:20:22 +0000

A good Idea would be to toggle a second pin between each send to make it obvious where each part ends if you are using a two or more channel oscilloscope.


josenuno

Thu, 13 Jun 2013 04:06:50 +0000

Hello,

Thank you for the replies. I am actually trying to control a stepper motor using one of the UART ports, so I used the driver Cytron SD02B. I send the commands from the chipKIT Max32 (using UART2) to the level converter MAX3232 (in order to convert from 3.3V, which is the output voltage from TX, to 5V), and then from the converter to the driver, but it seems like the driver's RX does not receive the right values. I am sure that all the connections between the driver and the motor are correct, so maybe the level converter is messing the values up. Also, I used a program provided by Cytron (http://www.cytron.com.my/viewProduct.php?pcode=SD02B), and it did not work (even though it should). Did you already use the chipKIT Max32 with the Cytron SD02B driver (sending commands through serial ports)? If yes, did you have such problems?

Thank you, Jose


majenko

Thu, 13 Jun 2013 08:46:01 +0000

The MAX3232 is a special kind of level converter. It converts TTL levels into RS232 levels - that is, 0=GND, 1=3.3V into 0=5V, 1=-5V (or thereabouts).

If your driver chip needs 5V TTL levels (which from that site it looks like it does), then that chip is not suitable. You need a proper level translator, or build your own - there are plenty of circuits available on the web, some better than others, and some more complex than others.

Are you sure you even need to translate the levels? Most 5V devices are happy with 3.3V as an input - it can be borderline sometimes, but usually OK.


pito

Thu, 13 Jun 2013 08:47:27 +0000

'A' Binary = 01000001 41 Hex add start bit = 101000001 add stop bit = 1010000010

Start bit is 0, and stop bit is 1 with serial uart, afaik.

'A' Binary = 01000001 41 Hex
add start bit = 001000001
add stop bit = 0010000011

PS: your driver board requires "TTL" uart levels - ie. the recommended UC00A interface is an FTDI based gadget with ttl output. Do not connect it via rs232 levels (MAX3232) as they are "inverted". ttl levels: "0" is 0V, "1" is 3.3V (or 5V) rs232 levels: "1" is -3..-12V, "0" is +3..+12V


majenko

Thu, 13 Jun 2013 09:15:22 +0000

This is SD02B’s UART receive pin. It should be interfaced to 5V logic UART. It should be connected to host’s transmit pin.

So definitely, do NOT use the MAX3232.