UART/CODE problem Oshonsoft

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Yes! Just place TXEN = 0 after your HSEROPEN command..( basically override it. )
Hi I,
It stops!
Note: When I say 'stops' I mean that the GPS is being read and PARSED, then sent to MASTER that HSEROUTs a STRING with GPS inside, and somewhere along the line it stops.

I'll now asnswer 'E's message, so I'll leave this for a while (one thing at a time :)
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
That is not the basic program and ASM result that I asked you to post

It was this with the CONFIG1H settings in the test program
; 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:
Hi E,
Is this correct?
C
Code:
; Compiled with: PIC18 Simulator IDE v4.42
; Microcontroller model: PIC18F4431
; Clock frequency: 32.0MHz
;
    ORG 0x000000
    BSF RCON,IPEN
    GOTO L0004
    ORG 0x000008
    RETFIE
    ORG 0x000018
    RETFIE
; User code start
L0004:
; 1: 'TEST 3
; 2:
; 3: Define CONFIG1H = 0x06  '8mHz x4 =32
;       The value of 'CONFIG1H' is 6
; 4:
; 5: 'actual basic test code.i used,
; 6: 'DEBUG 2
; 7: 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
; 8:
; 9: Loop:
L0001:
; 10:
; 11: Hserout
; 12:
; 13: vnop
; 14: Goto Loop
    BRA L0001
; Library code
L0008    BRA L0008
L0002:
    RETURN
L0003:
L0005:
    BTFSC PIR1,TXIF
    BRA L0006
    BRA L0005
L0006:
    MOVWF TXREG
    RETURN
L0003a:
L0007:
    MOVF POSTINC1,w
    BTFSC STATUS,Z
    RETURN
    RCALL L0005
    BRA L0007
    RETURN
; End of user code
L0009    BRA L0009
;
;
;
;
;
;
; Configuration settings
    ORG 0x300000
    DW 0x0600
    DW 0x200C
    DW 0x8004
    DW 0x0080
    DW 0xC00F
    DW 0xE00F
    DW 0x400F
; End of listing
    END
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi E and I,
If the https://forum.allaboutcircuits.com/threads/uart-code-problem-oshonsoft.195758/post-1849523
post is incorrect, please clarify how I go about it correctly.

I've changed both HSEROPEN and this method
-----------------------------------------------
''setup USART for baud receive
'RCSTA = %10010000 'SPEN (RCSTA<7>) bit must be set ( = 1),
'TXSTA.BRGH = 1
'BAUDCON.BRG16 = 0 '0 = 8-bit Baud Rate Generator – SPBRG only (Compatible mode), SPBRGH value ignored¦
'SPBRG = 51 '207
'PIR1.RCIF = 0
'PIE1.RCIE = 1
'PIE1.CCP1IE = 1
'INTCON.PEIE = 1
'INTCON.GIE = 1
-----------------------------------------------
but what ever I try the GPS still only works when set to 38400 BAUD.

Even when running, it still stalls, so I'm going to attemp to shorten the INTERRUPT.
C
 

jjw

Joined Dec 24, 2013
823
On ETO you said it stops after a few minutes?
Do you mean that PIC 18F4431 stalls?
Could be SPI problem.
Is the whole GPS message received by PIC18F4431 and stored before sending it through SPI?
Are there other interrupts running?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
On ETO you said it stops after a few minutes?
Do you mean that PIC 18F4431 stalls?
Could be SPI problem.
Is the whole GPS message received by PIC18F4431 and stored before sending it through SPI?
Are there other interrupts running?
Hi J,
I also said it stalls here, a while back.
To recap:
The 4431 SLAVE reads the GPS using RX PIN.
The message plus a QEI reading is PARSED.
The GPS data plus the QEI data, is sent to the 46K20 MASTER via SPI.
The MASTER sends this data, plus more, information, to a computer TERMINAL screen.
This information stalls after seconds to minutes, but the QEI data plus other stuff is sent, and a LED flashes.
It appears to me that it is the GPS reading, that is the problem?
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
I think oit's come to a nightmare scenario, where I've got to run a simple 4431 program, and get the BAUD to change, then introduce the rest of the full program, until it breaks, to find out where this problem triggers in.

EDIT: I cobbled a minimum program, which is only the 4431, and RX TX as normal.
1st test with the GPS 38400 and 9600, and outputting the DATA on a SEROUT PIN, showed gobbledegook.
It all needs checking etc
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,830
TUMBLEWEED says [From ETO]
"In your tests look for overrun errors. Your ISR must be fast enough to keep up with the GPS baud rate.
At 9600 baud that's about 1ms/byte, and at 38400 it's a quarter of that (roughly 250us).
If you have anything in the ISR that takes time (like uart or SPI output) you'll have to get rid of it because that will effect the timing in a big way.

I think the GPS is set to automatically transmit messages 4-5 times/second. With that, you can pretty much guarantee that at some point you're going to get an overrun error and have to resync your reception of the GPS data stream. "


Hi T,
I can change the BAUD rate and the output rate of the GPS. As mentioned it runs with the GPS set to 38400 BAUD, but not at 9600, which is puzzling.
I'm looking through all of the suggestions, and hopefully get it going.

Normally I can usually find problems by using the OSH SIM, but as this is internal, I just have to prod and poke.
C
 
Last edited:

sagor

Joined Mar 10, 2019
1,049
Remember that Serout is based on software timing loops and if your ISR is using up a lot of CPU time, Serout may not be reliable data, especially at higher speeds.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Remember that Serout is based on software timing loops and if your ISR is using up a lot of CPU time, Serout may not be reliable data, especially at higher speeds.
Hi S,
Ok, thanks.
SEROUT is only used for testing, so I can watch what's happening.
There is a NOKIA screen, that is in the program, that I could use, and will be switched in soon.
C
 
Top