Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

uart receive problems

Status
Not open for further replies.

robmitch

New Member
Hi all,
I am very new to microcontrollers,and I bought a Zilog Encore XP dev board. I need to interface it with a compass module using a uart port. I have tried to do it but have had no success yet.

I have initialised uart1, using the api, and enable the receive interrupts. I get an interrupt, and status register errors even if nothing is even connected to the port pins. I also get errors if the module is connected.

Am I meant to have pull-up/down resistors in place?

The compass module is a TTL module but requires 5v input - might I need a level converter?

What would be the normal start-up sequence for something like this - initialise everything, then apply power to compass module (it will start transmitting compass headings in continuous mode by default)?

Sorry if I have confused anyone, I am a little desparate
Cheers,
Rob
 
Hi all,
I am very new to microcontrollers,and I bought a Zilog Encore XP dev board. I need to interface it with a compass module using a uart port. I have tried to do it but have had no success yet.
Does the XP dev board have a RS232 line driver/receiver ic, eg: MAX232

I have initialised uart1, using the api, and enable the receive interrupts. I get an interrupt, and status register errors even if nothing is even connected to the port pins. I also get errors if the module is connected.

Am I meant to have pull-up/down resistors in place?

The compass module is a TTL module but requires 5v input - might I need a level converter?
IF the dev board has a level convertor [RS232 driver] the TTL signals will not be compatible

What would be the normal start-up sequence for something like this - initialise everything, then apply power to compass module (it will start transmitting compass headings in continuous mode by default)?
I would power up both modules at the same time and program the dev board to wait before reading the serial input, discard any corrupted data.

Sorry if I have confused anyone, I am a little desparate
Cheers,
Rob

hi,:)
I am assuming that the Zilog is operating with a +5V supply.?

If you have a link to the dev board circuit please post it.
 
Last edited:
Eric,
Dev board manual:
https://www.electro-tech-online.com/custompdfs/2009/07/um0151-1.pdf

Has a MAX232, but I thought I wold be able to connect the module directly to the uart pins of the mcu. Board & mcu descriptions and circuit in manual

Dev board runs on 5V supply, although regulated to 3.3V Vcc for zilog. I assumed that the compass module might do the same... what votage levels is TTL exactly?

Compass module:
https://www.electro-tech-online.com/custompdfs/2009/07/ProductFile_99-1.pdf

Am I dreaming, or should this be fairly simple?
Cheers,
Rob
 
Last edited:
Dev board runs on 5V supply, although regulated to 3.3V Vcc for zilog. I assumed that the module might do the same... what votage levels is TTL exactly?

hi,
Idealised TTL levels are 0V and +5V, but in practice are about 0.4V and +4V typically.

Does the Dev board have a RS232 driver ic.??
 
Hi,
You say that you are going to wire the Compass TTL onto the MCU side of the MAX232.
As you have already guessed, the MCU is running at 3.3V and the Compass at 5V, so the signal voltage levels are not compatible.

I would suggest the simple way way be to add a small MAX232 ic pcb and connect to the TTL i/o's of the compass.
Make the connection between the dev pcb and compass via RS232.

The advantage would be that the Compass could be placed some distance from the MCU dev pcb.

Do you follow OK.?:)

EDIT:

Look at this pdf for ideas.
 

Attachments

  • 3_3vto5vAnalogTipsnTricksBrchr.pdf
    952.8 KB · Views: 325
Last edited:
I assumed that the compass module had a regulator to 3.3v somewhere and the tx/rx pins would be 3.3v too (when I ordered the module I asked for one that I could interface directly to the controller). As well as this, I thought I would be fine if it was a 5v signal as the zilog pins are meant to be 5v tolerant...

Doesnt the MAX232 output -5v -> 12v or something for serial with computer?

I have just read your pdf re: 3.3v-5v - Tip#9 - OK to direct connect CMOS 3.3v, 5v tolerant pin to 5v TTL output

I was not going to use UART0 - which is connected to the MAX232, I was going to use UART1, which is on port D, and not connected yet.

Still a problem with this direct connection?
 
I assumed that the compass module had a regulator to 3.3v somewhere and the tx/rx pins would be 3.3v too (when I ordered the module I asked for one that I could interface directly to the controller). As well as this, I thought I would be fine if it was a 5v signal as the zilog pins are meant to be 5v tolerant...

Doesnt the MAX232 output -5v -> 12v or something for serial with computer?

I have just read your pdf re: 3.3v-5v - Tip#9 - OK to direct connect CMOS 3.3v, 5v tolerant pin to 5v TTL output

I was not going to use UART0 - which is connected to the MAX232, I was going to use UART1, which is on port D, and not connected yet.

Still a problem with this direct connection?

hi,
just looking at the Z8F datasheet, as you say you could use the 'free' uart pins on the MCU.

If you can confirm that the Z8F is 5V inoput tolerant that would solve the receive.
I cannot see on the Compass data where it says it can be run at 3.3V, just +5V.

I would suggest that you try driving the Compass input from the Z8F, it will not harm it.

On the Compass to Z8F line add a low value resistor, say 100R.

Look at this for levels.
http://www.interfacebus.com/voltage_threshold.html
 
Last edited:
Eric,
So i should put a 100 Ohm resistor in series on the tx line from the compass (rx pin on the mcu).
You say that shoud be ok for the receive, but the transmit...?

Also, driving the compass from the Z8 - do you meant supplying power to the compass module from one of the output pins of the Z8 (3.3v)? Would I also put a current limiting resistor there too?

What are your guesses with the serial protocol for that module - default 9600BAUD, 8 data bits, no parity, 1 stop bit, no flow control?

Sorry about all the (silly) questions
 
Eric,
So i should put a 100 Ohm resistor in series on the tx line from the compass (rx pin on the mcu).
This from the 5V TX line from the Compass module to the Dev pcb
[5V source driving a 3.3V input [but 5V a tolerant input]


You say that shoud be ok for the receive, but the transmit...?
The TX from the Dev pcb source is at 3.3V to a 5V input on the Compass.
Its worth a try to see if the Compass will accept a 3.3V input


Also, driving the compass from the Z8 - do you meant supplying power to the compass module from one of the output pins of the Z8 (3.3v)? Would I also put a current limiting resistor there too?
No I would NOT suggest that, power the Compass from 5V in order to meet the spec.

What are your guesses with the serial protocol for that module - default 9600BAUD, 8 data bits, no parity, 1 stop bit, no flow control?

Looking at the Compass datasheet, I cant see the RS232 data update rate, so I guess its just continous.?

Initially use the defaults 9600, is fast enough for a Compass.

Sorry about all the (silly) questions

hi,
Whats the compass going to used on, boat, car etc,???:)

The data dosnt say any form of software or handware handshaking is available.
 
Last edited:
tracking yaw angle of one's head, as a headtracker

One more: If the compass is transmitting 11 bytes per reading, how do i get all of those bytes - I can see how to getChar() from the rx data, pressumably everytime I get a rx interrupt, and I should keep doing this (11 times), then re-assemble the 11 bytes, converting to ascii and making sense of it from there?

I suppose it would be the same as if the tranmitter sent the string: "Heading112" - you would have to read 10 char values and put it back together? Or do you get a char pointer to the rx data -

char *pData = &getChar();
char cHundreds = pData[7];
char cTens = pData[8];
char cUnits = pData[9];
 
tracking yaw angle of one's head, as a headtracker

One more: If the compass is transmitting 11 bytes per reading, how do i get all of those bytes - I can see how to getChar() from the rx data, pressumably everytime I get a rx interrupt, and I should keep doing this (11 times), then re-assemble the 11 bytes, converting to ascii and making sense of it from there?

I suppose it would be the same as if the tranmitter sent the string: "Heading112" - you would have to read 10 char values and put it back together? Or do you get a char pointer to the rx data -

char *pData = &getChar();
char cHundreds = pData[7];
char cTens = pData[8];
char cUnits = pData[9];

hi,
The ASCII compass string is: $H,123*cc followed by CRLF 0Dh 0Ah

You have the option of a continous output, or output on demand by issuing a 'Order Word' P or n

I would issue a 'n' command and wait for a RXD received data Interrupt.
Sync the MCU string on the $ character and keep reading and storing the received compass data characters in a string until the 0Ah terminator is detected.

The string is ALREADY in ASCII format so it could be used to drive an LCD etc directly.

OK.?:)

EDIT:
Which programming language are you using, C ,asm etc.???
 
Last edited:
The way you would get the data into a string would be something along the line of,

Code:
char Buff[11];

void getString(){
char i;
    while(getChar()!=0x24);	//wait for start of packet
    for(i=0;i<10;i++){		//get 10 characters
        Buff[i]=getChar();	//and put them in the buffer
    }
}

As the $(0x24) isn't stored the hundreds digit would be at Buff[2].

Mike.
 
Last edited:
The way you would get the data into a string would be something along the line of,

Code:
char Buff[11];

void getString(){
char i;
    while(getChar()!=0x24);	//wait for start of packet
    for(i=0;i<10;i++){		//get 10 characters
        Buff[i]=getChar();	//and put them in the buffer
    }
}

As the $(0x24) isn't stored the hundreds digit would be at Buff[2].

Mike.

Mike,
Lovely... will try tonight. Suppose
char i;
should be
int i; //???

While I am at it, another silly question:
I connect the pin on the compass module marked RXD with the Zilog pin TXD, and vica-versa?
 
Mike,
Lovely... will try tonight. Suppose
char i;
should be
int i; //???

While I am at it, another silly question:
I connect the pin on the compass module marked RXD with the Zilog pin TXD, and vica-versa?

Char or Int doesn't matter but char uses less memory and is quicker.

Yes, cross connect RX and TX but you must remove the RS232 converter on the target board. You either need two level converters or none.

Edit, hadn't realised there is a second UART without a Max232 - that should work fine.

Mike.
 
Last edited:
I have conneced it all up, although when I read rx data, I only get, 00, as well as a framing error and overrun error, after a couple of reads. Also, that was after a lot of coaxing to get it to actually read uart1 instead of the default uart0...

It seems as though there is always one char available at startup (after entering main() ), even with the module unpowered (value also 00). Then, when I power the module, more become available (all 00, as mentioned). I tried in interrupt mode and polling mode.

Things arent as easy as I thought they might be :blush

I might start debugging by putting the compass module into an oscilloscope - I should make sure that is working first... I suppose that will work?

Also, I am using wire (around 3") between the dev board and the module - is that going to ruin the signal?
 
If you are getting framing and overrun errors then I would check your baud rate. To check the compass is doing as you expect you can connect it to a PC via a MAX232 and use hyperterminal to view the output.

Edit, I just looked at the data sheet for your compass and it doesn't state the baud rate or if the TTL levels are inverted. If you have a scope then you should be able to work them out.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top