GPS trouble SCI reception in HCS08QG8

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPS trouble SCI reception in HCS08QG8

Jump to solution
589 Views
mauromoreyra
Contributor I

Hi everybody!, i'm form Argentina and this is my first time posting in the forum...

 

I'm working on QG8 microcontroller, and i have problems trying communicating with a GPS module (ET-332 of GlobalSat). Specifically, while the program runs and de RX pin is receiving GPS data string, it doesn't enters in the RX interrupt subroutine (

 

I've verified that RX pin is receiving data from GPS transmitter (@4800 bauds) with a scope.

 

This is my interrupt subroutine code of the RX in assembler:

 

sci_rx_isr:

            lda   SCIS1          ; clear RDRF flag

            lda   SCID          ; clear RDRF flag

            mov   SCID,X+     ; data vector from GPS

            cpx   #68         ; string length

            bne   no_end

            ldhx  #RMC_string ;  start again when 68 bytes string data is complete

no_end:            

            rti

 

 

Also I've verified many times the configuration of the SCI registers, and is OK. The bus frequency is 2.4576 MHz and BR bits value is 32. Here is my initialization code of the SCI module.

 

mov   #$00,SCIBDH ;

mov   #$20,SCIBDL ; BR [SBR12:SBR0] = 32

           

mov   #%00000000,SCIC1 ; 8 data bits, no parity bit

; LOOPS = 0 (Normal operation — RxD and TxD use separate pins)

; SCISWAI = 0 (SCI clocks freeze while CPU is in wait mode)

; RSRC = 0 (util solo cuando LOOPS = 1)

; M = 0 (Normal — start + 8 data bits (LSB first) + stop)

; WAKE = 0 (Idle-line wakeup)

; ILT = 0 (Idle character bit count starts after start bit)

; PE = 0 (No hardware parity generation or checking)

; PT = 0 (util solo cuando PE = 1)

           

mov   #%00100100,SCIC2 ; interrupt enabled when RDRF flag = 1, RxD SCI receiver enabled

; TIE = 0 (Hardware interrupts from TDRE disabled (use polling))

; TCIE = 0 (Hardware interrupts from TC disabled (use polling))

; RIE = 1 (Hardware interrupt requested when RDRF flag is 1), se genera interrupción cuando se completa la recepción de un dato en el registro SCID

; ILIE = 0 (Hardware interrupts from IDLE disabled (use polling))

; TE = 0 (Transmitter OFF)

; RE = 1 (Receiver ON)

; RWU = 0 (Normal SCI receiver operation)

; SBK = 0 (Normal transmitter operation)

           

mov   #$00,SCIC3  ; no interrupts generated by errors

 

 

 

 

Someone can help me??

 

Thanks!!

 

 

Labels (1)
Tags (3)
0 Kudos
1 Solution
348 Views
bigmac
Specialist III

Hello,

I can see a number of problems with your code -

  1. When you first enter an ISR, the value of the H-register needs to be saved to the stack, and then the original H-register value re-instated prior to exiting the ISR.  This is not automatically done by the interrupt process.  Since you indend using indexed instructions within the ISR, it is mandatory to do this.
  2. As has already been pointed out, you seem to be assuming that the SCI receive buffer commences at address zero.  This is not allowed since the MCU registers occupy the lower portion of the direct addressing range.  Since you will need to keep track of the number of characters currently within the buffer, the use of indexed addressing mode, with zero offset, will add to the code complexity.  I suggest that an indexed addressing mode, with offset, would be more appropriate in this case.  The offset value would represent the start address of the buffer, and the H:X value the current position within the buffer.
  3. The incremented position in the buffer will need to be saved prior to exiting the ISR, and then re-loaded at the start of the next interrupt.
  4. When the string data is completed, you will need to communicate this to the main program loop.  A flag bit could be used for this purpose, which would be polled to determine when a new data string was available.
  5. You have not indicated whether you already have the required vector table entry for the SCI ISR?

The following code snippet assumes absolute addressing mode is used.

; Equates:

CODE     equ  ROMStart

BUFLEN   equ  68

RXEND    equ  0

; Variables:

  ORG    Z_RAMStart             ; Zero-page RAM
Rxbuf:   ds.b BUFLEN

Rxcnt:   ds.b 1

flag:    ds.b 1                 ; Single bit flags

; Start of code:

  ORG    CODE                   ; Flash address where code commences

; Other code here

; ISR code:

SCIRX_ISR:

         pshh                   ; Save current value

         clrh

         ldx     Rxcnt          ; Current position in buffer

         lda     SCIS1          ; Preparatory to clearing flag

         lda     SCID           ; Also clears flag

         sta     Rxbuf,x        ; Current byte to buffer

         incx

         cpx     #BUFLEN

         bne     SRI1           ; Branch if data packet not complete

         clrx                   ; Ready for next packet

         bset    RXEND,flag     ; Set flag

SRI1:    stx     Rxcnt          ; Save current position in buffer

         pulh                   ; Restore prior value

         rti

; Other code here

; Vector entries:

  ORG    Vscirx

         dc.w    SCIRX_ISR

  ORG    Vreset

         dc.w    Main_start     ; Start address of main code loop

Regards,

Mac

View solution in original post

0 Kudos
2 Replies
349 Views
bigmac
Specialist III

Hello,

I can see a number of problems with your code -

  1. When you first enter an ISR, the value of the H-register needs to be saved to the stack, and then the original H-register value re-instated prior to exiting the ISR.  This is not automatically done by the interrupt process.  Since you indend using indexed instructions within the ISR, it is mandatory to do this.
  2. As has already been pointed out, you seem to be assuming that the SCI receive buffer commences at address zero.  This is not allowed since the MCU registers occupy the lower portion of the direct addressing range.  Since you will need to keep track of the number of characters currently within the buffer, the use of indexed addressing mode, with zero offset, will add to the code complexity.  I suggest that an indexed addressing mode, with offset, would be more appropriate in this case.  The offset value would represent the start address of the buffer, and the H:X value the current position within the buffer.
  3. The incremented position in the buffer will need to be saved prior to exiting the ISR, and then re-loaded at the start of the next interrupt.
  4. When the string data is completed, you will need to communicate this to the main program loop.  A flag bit could be used for this purpose, which would be polled to determine when a new data string was available.
  5. You have not indicated whether you already have the required vector table entry for the SCI ISR?

The following code snippet assumes absolute addressing mode is used.

; Equates:

CODE     equ  ROMStart

BUFLEN   equ  68

RXEND    equ  0

; Variables:

  ORG    Z_RAMStart             ; Zero-page RAM
Rxbuf:   ds.b BUFLEN

Rxcnt:   ds.b 1

flag:    ds.b 1                 ; Single bit flags

; Start of code:

  ORG    CODE                   ; Flash address where code commences

; Other code here

; ISR code:

SCIRX_ISR:

         pshh                   ; Save current value

         clrh

         ldx     Rxcnt          ; Current position in buffer

         lda     SCIS1          ; Preparatory to clearing flag

         lda     SCID           ; Also clears flag

         sta     Rxbuf,x        ; Current byte to buffer

         incx

         cpx     #BUFLEN

         bne     SRI1           ; Branch if data packet not complete

         clrx                   ; Ready for next packet

         bset    RXEND,flag     ; Set flag

SRI1:    stx     Rxcnt          ; Save current position in buffer

         pulh                   ; Restore prior value

         rti

; Other code here

; Vector entries:

  ORG    Vscirx

         dc.w    SCIRX_ISR

  ORG    Vreset

         dc.w    Main_start     ; Start address of main code loop

Regards,

Mac

0 Kudos
348 Views
jsmcortina
Contributor III

The first thing that strikes me is that you aren't loading anything into H:X ? Surely you need to set that ?

e.g.

----------------

sci_rx_isr:

            lda   SCIS1          ; clear RDRF flag

;            lda   SCID          ; clear RDRF flag

            ldhx   global_u16_address_variable

            mov   SCID,X+     ; data vector from GPS

            cpx   #68         ; string length

            bne   no_end

            ldhx  #RMC_string ;  start again when 68 bytes string data is complete

no_end:           

            sthx   global_u16_address_variable

            rti

----------------

I've commented the lda SCID as you are trying to read it twice - each read clears the buffer. I'm assuming that the mov will be valid. If not replace with:

lda SCID

sta ,x

aix #1

Also, your code is going to write to the start of memory - is that what you actually want? You might want a counter and an address that get added together.

Hope that helps

James