Jon Chandler
- Joined Jun 12, 2008
- 1,596
Might the PIC UART not correctly interpret the x4 clock multiplier? If it thinks the clock speed is 8MHz when in fact it's 32MHz, what it thinks is 9600 baud will be 38,400 baud.
Hi J,Might the PIC UART not correctly interpret the x4 clock multiplier? If it thinks the clock speed is 8MHz when in fact it's 32MHz, what it thinks is 9600 baud will be 38,400 baud.
Morning E,Hi C,
The PIC datasheets, show the 4* clock drives all the peripherals.
Note the compensating text image.
E
View attachment 302394ll
Hi E,Hi C,
I would suggest the following test.
Write a short/simple Oshonsoft program, using the PIC type which is giving the Serial data problem.
Program the PIC to transmit at 9600 baud, via its internal UART a typical GPS message at say 1 message/sec.
Use this programmed PIC to emulate the normal input from from your GPS module into your main PIC.
You can use your Logic analyser to check for timing/transmission errors
E
Hi S,Oshonsoft compiler calculates the baud rate values from your “Crystal” frequency declaration (Define) in your code when you use a Hseropen statement. Not sure if you declare actual crystal or the 4x PLL frequency however….
Hi E,Hi C,
When you use HSEROPEN, compile as usual, then look at the ASM file that the compiler created.
It shows you what the HSEROPEN created.
E
Example:
; 4: Hseropen 9600
; exact baud rate achieved = 9603.84153; bit period = 104.125µs; baud rate error = 0.04%
BSF TRISC,6
BSF TRISC,7
MOVLW 0x40
MOVWF SPBRG
MOVLW 0x03
MOVWF SPBRGH
CLRF BAUDCON
BSF BAUDCON,BRG16
MOVLW 0x24
MOVWF TXSTA
MOVLW 0x90
MOVWF RCSTA
; 5:
Actual Basic test Code. I used,
'DEBUG 2
Hseropen 9600
Loop:
nop
Goto Loop
Hi E,Hi C,
BSF TRISC,6 makes this pin an Input.
Examples:
Control registers, called TRISA, for Port A and TRISB for Port B, determine whether the port is an input or an output, (or a mixture.)
Writing logic 1 into a bit of TRISA causes the corresponding bit of Port A to input data.
Logic 0 makes the corresponding bit output data.
TRISB controls Port B in the same way.
TRIS stands for TRIState. It means the port is waiting for an input
rather than output a high or low signal. It's named as such because a port can have 3 states: Output High. Output Low.
Hi I,Transmission is just a term. the GPS and Pic have a "transmission" whether the receiver is one or transmitter is one the other or both. Saying that, you can view the periods between the transmission by scope.
I'll explain... The GPS will spew a sentence out with a terminator. You close in on that terminator and parse the sentence.
If the quiet period is long enough, by all means do it in the interrupt.. Set your scope to .5hz and watch the serial data
View attachment 302271
Two packets with a quiet time between.. That's the time when the buffer needs parsing, that's your window.
In C, I could probably do a 30 byte buffer in a quarter less time. Not saying Vlads compiler work is inefficient but it wont be as efficient as a decent C compiler optimised to the hilt. If the next string arrives while the interrupt is busy the first bit, let alone byte, will throw it out of sync. If you can use a ring buffer and wait for a start and also an end it'll be more concrete.
Look at the GPS document. You may be able to set the transmission delays giving more time to sort yourself out.
I once did a modbus job, ModBus over ethernet, but the packets were required every 100mS so I struggled to do anything. most of the time ( pic18) was just preping for modbus.
Hi E,hi C,
Read Section 9.4 on this PDF.
E
I edited #38, hope it now makes sense.Hi C,
I read it and it make things complicated, inoutoutin?
When you post a query, please explain what part don't you understand, so that we can give a meaningful answer.