Need help with SCI communications

General problems? Ask here!

Moderator: cbarnes

Need help with SCI communications

Postby tdub » Mon Oct 22, 2007 3:21 pm

Hi,

I am trying to interface a serial GPS engine board with the NanoCore MaxC32.

For reference, the GPS unit used in this case is:

UsGlobalSat EM406A

I used a MAX3232 chip to translate the TTL levels used for the GPS to the RS232 levels used by the nanocore.

By default, the GPS operates at 4800 bps, 1 stop bit, no pairity.

I can transmit to the GPS properly. When I send the reset command out on the SCI, the GPS unit LED indicates that it has been reset.

However, I cannot receive the data coming out of the GPS. I can see that there is in fact a signal on the RX pin but the RDRE flag in SCISR1 is never set. The voltage levels seem correct for all the TX and RX pins on both the GPS and micro.

Does anyone know what I could do to troubleshoot this problem?

Here is the code I used to test the GPS:

REGBASE equ $0
RAMBASE equ $3800
INITRM equ $0010 ; RAM Position
INITRG EQU $0011 ; Register position

;SCI Registers

SCIBDH equ $00C8
SCIBDL equ $00C9
SCICR1 equ $00CA
SCICR2 equ $00CB
SCISR1 equ $00CC
SCISR2 equ $00CD
SCIDRH equ $00CE
SCIDRL equ $00CF

;PLL Registers

SYNR equ $34
REFDV equ $35
CRGFLG equ $37
CLKSEL equ $39
PLLCTL equ $3A
COPCTL equ $3c

org $3800

myflag rmb 1
mychar rmb 1

org $8000 ; start of program memory

BadInt ; handle UNexpected interrupts...
rti

startup_code

sei ; Disable interrupts
movb #$00,INITRG ; set registers to $0000
movb #$39,INITRM ; init RAM ($3800 - $3fff)
lds #$3fce ; init stack
cli

bclr CLKSEL, #$80 ; disengage PLL to system
bset PLLCTL, #$40 ; turn on PLL
movb #$2, SYNR ; set PLL multiplier
movb #$0, REFDV ; set PLL divider
nop
nop
brclr CRGFLG,#$08,>*+0 ; while (!(crg.crgflg.bit.lock==1))
bset CLKSEL, #$80 ; engage PLL to system

serial_setup:

;BUSCLK is running at 24MHz, so we'll base all speeds on that.

movb #$01,SCIBDH ; set the SCI baud rate to 9600 bits/sec
movb #$38,SCIBDL ; 9600=24x10^6/(16*156), $9c=156
movb #$0c,SCICR2 ; Turn on the SCI transmitter and receiver

;------------------------------------------------------------------
; User Program
;------------------------------------------------------------------

USER_START:
clr mychar
jsr d_xms
load_command:
ldx #mystr ; load the command string that resets the GPS
next_char:
ldab $00,x
cmpb #$00
beq load_char

tx_wait:
brclr SCISR1,#$80,tx_wait ; wait for the TDRE bit to go high

stab SCIDRL
inx
jsr d_xms
jmp next_char ; go set up for next character


load_char:
brclr SCISR1,#$20,load_char ; wait for the RDRE bit to go high
ldab SCIDRL
stab mychar

jsr d_xms

tx_wait1:
brclr SCISR1,#$80,tx_wait1 ; wait for the TDRE bit to go high

ldab mychar
stab SCIDRL
jsr d_xms
jmp load_char ; go set up for next character

d_xms: ldab #100 ; delay 100 ms

dly1: ldy #6000 ; (6000 = 1ms @ 24,000 cycles)
dly: dey ; 1 cycle
bne dly ; 3 cycles
decb
bne dly1
rts

mystr fcc '$PSRF100,0,4800,8,1,0*0C'
fcb $0d,$0a
;fcc '$PSRF102,4800,8,1,0*12'
;fcb $0d,$0a
fcc '$PSRF103,00,01,00,00*25'
fcb $0d,$0a
fcc '$PSRF101,-2686700,-4304200,3851624,96000,497260,921,12,3*1C'
;fcc '$PSRF101,0,0,0,000,0,0,12,1*15' ;hot start
;fcc '$PSRF101,0,0,0,000,0,0,12,8*1C' ;factory reset
fcb $0d,$0a
Nul fcb $00

; ------------------ VECTOR TABLE --------------------
org $FF8A
fdb BadInt ;$FF8A: VREG LVI
fdb BadInt ;$FF8C: PWM emergency shutdown
fdb BadInt ;$FF8E: PortP
fdb BadInt ;$FF90: Reserved
fdb BadInt ;$FF92: Reserved
fdb BadInt ;$FF94: Reserved
fdb BadInt ;$FF96: Reserved
fdb BadInt ;$FF98: Reserved
fdb BadInt ;$FF9A: Reserved
fdb BadInt ;$FF9C: Reserved
fdb BadInt ;$FF9E: Reserved
fdb BadInt ;$FFA0: Reserved
fdb BadInt ;$FFA2: Reserved
fdb BadInt ;$FFA4: Reserved
fdb BadInt ;$FFA6: Reserved
fdb BadInt ;$FFA8: Reserved
fdb BadInt ;$FFAA: Reserved
fdb BadInt ;$FFAC: Reserved
fdb BadInt ;$FFAE: Reserved
fdb BadInt ;$FFB0: CAN transmit
fdb BadInt ;$FFB2: CAN receive
fdb BadInt ;$FFB4: CAN errors
fdb BadInt ;$FFB6: CAN wake-up
fdb BadInt ;$FFB8: FLASH
fdb BadInt ;$FFBA: Reserved
fdb BadInt ;$FFBC: Reserved
fdb BadInt ;$FFBE: Reserved
fdb BadInt ;$FFC0: Reserved
fdb BadInt ;$FFC2: Reserved
fdb BadInt ;$FFC4: CRG self-clock-mode
fdb BadInt ;$FFC6: CRG PLL Lock
fdb BadInt ;$FFC8: Reserved
fdb BadInt ;$FFCA: Reserved
fdb BadInt ;$FFCC: Reserved
fdb BadInt ;$FFCE: PORTJ
fdb BadInt ;$FFD0: Reserved
fdb BadInt ;$FFD2: ATD
fdb BadInt ;$FFD4: Reserved
fdb BadInt ;$FFD6: SCI Serial System
fdb BadInt ;$FFD8: SPI Serial Transfer Complete
fdb BadInt ;$FFDA: Pulse Accumulator Input Edge
fdb BadInt ;$FFDC: Pulse Accumulator Overflow
fdb BadInt ;$FFDE: Timer Overflow
fdb BadInt ;$FFE0: Standard Timer Channel 7
fdb BadInt ;$FFE2: Standard Timer Channel 6
fdb BadInt ;$FFE4: Standard Timer Channel 5
fdb BadInt ;$FFE6: Standard Timer Channel 4
fdb BadInt ;$FFE8: Standard Timer Channel 3
fdb BadInt ;$FFEA: Standard Timer Channel 2
fdb BadInt ;$FFEC: Standard Timer Channel 1
fdb BadInt ;$FFEE: Standard Timer Channel 0
fdb BadInt ;$FFF0: Real Time Interrupt (RTI)
fdb BadInt ;$FFF2: IRQ (External Pin or Parallel I/O) (IRQ)
fdb BadInt ;$FFF4: XIRQ (Pseudo Non-Maskable Interrupt) (XIRQ)
fdb BadInt ;$FFF6: Software Interrupt (SWI)
fdb BadInt ;$FFF8: Illegal Opcode Trap ()
fdb startup_code ;$FFFA: COP Failure (Reset) ()
fdb BadInt ;$FFFC: Clock Monitor Fail (Reset) ()
fdb startup_code ;$FFFE: /RESET
tdub
Newbie
Newbie
 
Posts: 6
Joined: Sat Mar 03, 2007 5:08 pm

Postby cbarnes » Tue Oct 23, 2007 11:01 am

Looks like your code will never leave this loop:

load_char:
brclr SCISR1,#$20,load_char ; wait for the RDRE bit to go high
ldab SCIDRL
stab mychar

jsr d_xms

tx_wait1:
brclr SCISR1,#$80,tx_wait1 ; wait for the TDRE bit to go high

ldab mychar
stab SCIDRL
jsr d_xms
jmp load_char ; go set up for next character
cbarnes
Admin
Admin
 
Posts: 79
Joined: Mon Jul 26, 2004 10:28 pm
Location: Toronto

Postby tdub » Tue Oct 23, 2007 11:08 am

That's the whole point. I want it to load the characters transmitted from the GPS and print them out on the terminal.

I don't see what your point is.
tdub
Newbie
Newbie
 
Posts: 6
Joined: Sat Mar 03, 2007 5:08 pm

Postby cbarnes » Tue Oct 23, 2007 1:32 pm

Sorry, I didn't read carefully. But if the GPS is transmitting at 4800 baud, why are you inserting a 100mS delay after each character you successfully receive? It's ok to insert a delay when sending to the GPS, but when receiving, you have to take the characters as they come (you don't need to add a delay-- that's what the RDRF flag is for). I think you are missing the rest of the character string while you're delaying...
cbarnes
Admin
Admin
 
Posts: 79
Joined: Mon Jul 26, 2004 10:28 pm
Location: Toronto

Postby tdub » Tue Oct 23, 2007 1:46 pm

That makes sense. Thanks for your reply. I will remove the delay and see if that fixes the problem. However, I cannot get even 1 character received in the SCIDRL register. So, basically it polls infinitely or until i press a key on the keyboard. As I see it, the 9S12 does not see a signal on the RX pin even though the GPS is sending it and a multimeter shows there is a signal present. Any ideas?
tdub
Newbie
Newbie
 
Posts: 6
Joined: Sat Mar 03, 2007 5:08 pm

Postby tdub » Tue Oct 23, 2007 1:48 pm

I base the above on this code:

load_char:
brclr SCISR1,#$20,load_char ; wait for the RDRE bit to go high

The RDRE bit is never set. I have done some testing to see if the bit ever gets set and it does not. The only way it gets set is if I hit a key on the keyboard.
tdub
Newbie
Newbie
 
Posts: 6
Joined: Sat Mar 03, 2007 5:08 pm

Postby cbarnes » Wed Oct 24, 2007 2:38 pm

Just for the record, it should be RDRF (i.e. Receive Data Register Full). See the data sheet (section 13.5.2.2.3 RDRF Description)

In fact, read all of section 13.4., because there are several cases that mimic what you are seeing (Receiver Wakeup, Single-Wire Operation, Loop Operation, etc.) and they all revolve around bits in SCICR1 (which I noticed you never initialized).

Another thing I recall doing in my HC11 days was flushing the receive buffer by doing a dummy read operation in the SCI initialization code.
cbarnes
Admin
Admin
 
Posts: 79
Joined: Mon Jul 26, 2004 10:28 pm
Location: Toronto


Return to General Problems

Who is online

Users browsing this forum: No registered users and 3 guests

cron