Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 20th July 2009, 04:14 PM   #16
Default

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 by Pommie; 20th July 2009 at 04:20 PM. Reason: Had Buff[i]==getChar();
Pommie is online now  
Old 21st July 2009, 03:10 AM   #17
Default

Quote:
Originally Posted by Pommie View Post
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?
robmitch is offline  
Old 21st July 2009, 04:13 AM   #18
Default

Quote:
Originally Posted by robmitch View Post
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 by Pommie; 21st July 2009 at 08:17 AM.
Pommie is online now  
Old 21st July 2009, 11:41 PM   #19
Default

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?
robmitch is offline  
Old 22nd July 2009, 06:41 AM   #20
Default

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 by Pommie; 22nd July 2009 at 06:53 AM.
Pommie is online now  
Old 22nd July 2009, 09:21 AM   #21
Default

contacted manufacturer. default baud9600, one stop bit, no parity... which is what i was using. Will try and look with scope, but might take a while to get one to use...
robmitch is offline  
Old 22nd July 2009, 09:48 AM   #22
Default

Quote:
Originally Posted by robmitch View Post
contacted manufacturer. default baud9600, one stop bit, no parity... which is what i was using. Will try and look with scope, but might take a while to get one to use...
hi Rob,

If you connect a MAX232 to the Compass output you will be able to use a PC to communicate with the Compass.
__________________
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 22nd July 2009, 12:08 PM   #23
Default

Quote:
Originally Posted by robmitch View Post
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.
...
That is a pretty common problem, getting a 0x00 on startup with a framing error, it means something is holding that pin low at startup.

Try putting a delay in your startup code where you set the pin directions, then the delay (this lets the pin voltages settle etc), THEN initialise the UART.

I'm not sure why you get the same problem "after a couple of reads" but I would definitely look at the problem happening at startup first, that might lead to solving the second problem.
Mr RB is offline  
Old 23rd July 2009, 03:31 PM   #24
Default

It's alive! My first microcontroller interface!

Thanks guys. I ended up relaying everything from compass on UART1 to hyperterminal via UART0 and its max232. Wasnt getting any readings, and checked connections again... I think they have mis-labelled the rx/tx pins on the compass module, because it works now having swapped the lines - so now they are not crossed-over (rx-rx and tx-tx). Then again, I have been known to get things wrong when it comes to connecting things on the opposite side of a board to the drawing, when a 50/50 chance will get it wrong...

Some output:
Next Reading
$H,109*3A
Next Reading
$H,110*32
Next Reading
$H,110*32
Next Reading
$H,106*35

(Mike, my getChar() routine sent the received char to the hyperterminal, so thats why the $ appears in above readings)

The 109, 110, and 106 are heading degrees

Wow, this site and you guys are awesome. Standby for more problems from me.
Cheers,
Rob
robmitch is offline  
Old 25th July 2009, 04:02 PM   #25
Default

i have a problem whith the boudrate when i am using the soft uart of pic mcu
plz i need a help
engiah is offline  
Old 26th July 2009, 02:17 AM   #26
Default

engiah,
I am pretty new myself. I havent used a software uart. Maybe someone else here can help you out.
Cheers,
Rob
robmitch is offline  
Old 26th July 2009, 10:54 PM   #27
Default

I have a couple of projects on my page that use a soft uart on PIC.

This one uses PIC 16F876 in assembler and sends 31250 baud for MIDI;
(it says C but the uart "send byte" code is in assembler)
MIDI-Bash2 MIDI drum controller

This page has 4 projects in C. Project3 sends and receives software uart;
Connect JuneBug to serial port and Sharp GP2 sensor
Mr RB is offline  
Old 28th July 2009, 06:59 PM   #28
Default

THX 4 u rob
and THX 4 u MR RB
engiah is offline  
Old 20th October 2009, 12:40 AM   #29
Default

sir robmitch,
can u post ur code on receiving data from the compass?, im also dealing with the same problem about the electronic compass. can i become ur apprentice?!!
skidd10 is offline  
Old 20th October 2009, 06:00 AM   #30
Default

skidd10,
are you using the same compass module?
robmitch is offline  
Reply

Tags
problems, receive, uart

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
PIC 16F877 UART receive yueying_53 Micro Controllers 0 19th October 2008 08:52 AM
How can I Transmit/ Receive BCD noman_dk Electronic Projects Design/Ideas/Reviews 3 23rd February 2008 05:59 PM
Receive data via SPI Sam Jelfs Micro Controllers 2 11th April 2007 06:33 AM
receive data from other pic janetsmith2000@yahoo.com Micro Controllers 1 24th March 2004 07:28 PM
receive 0 data from UART..... wingbar General Electronics Chat 5 15th March 2004 07:11 PM



All times are GMT. The time now is 04:26 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker