hc12 sci PROBLEM

Hi all,

I'm currently using a HC912 EVB board to transmit the data converted from ADC to SCI and then transmit to the PC, hoping PC will get the data and display. But it seems nothing is received on PC, although the D-bug 12 is shown in Hyperterminal, while the program is executed, only thing I can see is User breakpoint encountered, and none of the data is received. I tried MS kermit also, same thing happened with a slightly different detail that in Kermit, PC retries a lot to receive the packet but end up with failure. Could someone experienced this give me some advice? Thank a lot!

Jessie

Reply to
Jessie
Loading thread data ...

BTW, I also found a response in D-bug 12 shown in hyperterminal, as MG S, does anyone know what it is supposed to mean?

Reply to
Jessie

Are you trying to send the data over the same SCI port that D-Bug 12 is using?

If so, is that supposed to be possible?

Reply to
cs_posting

I think you can take over the port, but failing that you can at least send chars to the terminal by calling the proper d-bug12 subroutine that lets you send chars. Look at the d-bug12 PDF for details on its public subroutines.

Reply to
Eric

Thank you very much Eric. That's a very good idea. But what I wanted to do is using SCI as a channel to transmit data converted from ADC to PC and then display it on PC. In other words, PC doesn't need to send data to SCI. The problem of my single SCI subroutine is it's lack of some breakpoints, after I set some software interrupt, it seems to function well.Now I'm testing the program with AD conversion step by step, another long way to go I guess..

Jessie

Reply to
Jessie

Are you waiting for each character to be done, before you try to send another?

If you aren't, your code might normally fail by overwriting the output register before it can be sent, but then start working if you add additional things to slow the processor down so that it can't write another character before the previous one has been fully shifted out.

Here's a character send routine for an HC9S12NE64

while (!(sciaSR1 & 0x80)) ; //wait while transmit register non-empty sciaDRL=char_to_send;

Reply to
cs_posting

To cs_post,

Thank you for your advice. Unfortunetely,I'm running asembly code and I did put a small delay routine when gathering the data to PC. If I comment the ADC conversion subroutine, the SCI program will function well, but if I let the ADC conversion program run, the program in Hyperterminal will just stuck and freeze. I checked my ADC program, and make sure there's no error. Still trying..

Jessie

Reply to
Jessie

Hi all,

Does anybody know if it's better to use SPI other than SCI to display the result from Analog to digital converter?

Jessie

Reply to
Jessie

Either is supported just fine by the HC12, so use whichever is supported by what you are talking to.

You might want to avoid using the micro as an SPI slave device though

- that can be harder to get working than SPI master mode, or SCI.

Reply to
cs_posting

Hi all,

I gave up the assembly code and use C to program the AD coverter then using printf() to display on my screen. This time I chose codewarrior as my compiler, and the program passed comipling without error. While I use the full simulation s19 file to load to the hc12evb chip, it always returns the error "can't write target memory". Should I change the EVB mode to Jump EEPROM mode or POD mode? I moved the jumper on W3 to 1, but wierdly, the mode remained in EVB mode. I'm really lost. Then I checked the chip's name, it's XC68HC912B32, while when I checked its doc in freescale, it said this chip is not produced any more. Have someone ever used about this chip and give some advice? I appreciate any of your help!

Jessie

Reply to
Jessie

You probably shouldn't be loading a simulation hex file into an actual chip.

Codewarrior projects support multiple targets. Change the target to one suitable for your BDM pod or serial loader.

As for the chip versions, you'll need to check that the special function registers for the ADC and the serial are all at the proper addresses for the chip you have.

Reply to
cs_posting

To cs_post,

Thanks for your continous help. I tried the SCI port again and again,it just cannot function well to when apply to the ATD converter. Can anyone help me to check the code below? First I initiate the SCI port and the ATD converter, once the comment string is transfered, I'll let SCI go and read the ATD result from the ADR register. Do I need to set up some breakpoint or synchronization during the programing?

ORG $0800 FCB $07 ORG $820

;ATD registers; ATDCTL1 EQU $0061 ATDCTL2 EQU $0062 ;used to select power-up mode; (ADPU,AFFC,AWAI,0,0,0,ASCIE,ASCIF) ATDCTL3 EQU $0063 ;used to select freeze control; (0,0,0,0,0,0,FRZ1,FRZ2) ATDCTL4 EQU $0064 ;used to select sample time bit and total divisor ATDCTL5 EQU $0065 ;used to select conversion modes, channels and initiate conversions ;(0,S8CM,SCAN,MULT,CD,CC,CB,CA)

ADR2H EQU $0074 ;Result registers

ATDSTATH EQU $0066 ;SCF implemented, sequence complete flag

;SCI registers; SC0BDL EQU $00C1 SC0CR1 EQU $00C2 SC0CR2 EQU $00C3 SC0SR1 EQU $00C4 SC0DRH EQU $00C6 SC0DRL EQU $00C7

;ORG $0D00 MAIN: ;LDAB #$FF BSR INIT_SCI ;Branch to INIT to initialize ATD BSR TRANS ;Branch to CONVERT for ATD conversion BSR INIT BSR CONVERT

BSR TRANS2 ;BSR DELAY2 ;DECB BSR DELAY2 BSR MAIN

SWI END

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;subroutine to initiate adc; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

INIT LDAA #$80 ;Load $80 to ATDCTL2 to power up ATD STAA ATDCTL2

BSR DELAY ;Delay 100us for the capacitors charging

LDAA #$00 ;Load $00 to ATDCTL3 to select the continue conversion mode,NO FREEZE STAA ATDCTL3

LDAA #$01 ;8-bit operation, 2 ATD clock STAA ATDCTL4 ;total divisor as 4 RTS

;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROURTINE DELAY 100us; ;;;;;;;;;;;;;;;;;;;;;;;;;;

LDAA #$C8

DELAY: DECA BNE DELAY RTS

JMP INIT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;subroutine convert; ;-----------------------------------; ;set up ATD, make single conversion and store the result to a memory location. ;configure and start ATD conversion ;Analog input signal: on port AD6 ;convert:using single channel, non-continuous ;The result will be located in ADR2H

CONVERT:LDAA #$06 ;Initiate ATD scan=0, mult=0, pad6 STAA ATDCTL5 WTCONV NOP BRCLR ATDSTATH,#$80,WTCONV ;Wait for sequitence complet flag

LDD ADR2H ;Load conversion result from ADR2H,results in accumulator D STD READING ;STORE D IN LOCATION READING BRA CONVERT ;Contiously updates results

RTS ;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROURTINE DELAY 100us; ;;;;;;;;;;;;;;;;;;;;;;;;;;

DELAY2 LDY #$FFFF L1 DEY BNE L1

DEC $800 BNE DELAY2 RTS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROUTINE TO INITIATE SCI; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; INIT_SCI:TPA ;transfer CCR to A accumulator ORAA #$10 ;Ored A with #$10 to set I bit TAP ;Transfer A to CCR

MOVB #$34,SC0BDL ;SET baud=9600 MOVB #$00,SC0CR1 ;Initialize for 8-bit data format

MOVB #$08,SC0CR2 ;set for no Ints, and transmitter enabled SC1CR2 LDX #COMMENT ;TRANSFER THE COMMENT

LDY #READING ;TRANSFER THE READING RESULT LDAA SC0SR1 ;1st step to clear TDRE flag:read SC0SR1 STD SC0DRH ;2nd step to clear TDRE flag: write SC0DR register RTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUBROUTINE TO TRANSMIT THE DATA STORED IN X; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; TRANS NOP BRCLR SC0SR1,#$80,TRANS ;Wait for TDRE flag

MOVB 1,X+,SC0DRL

CPX #$0B12 BNE TRANS

RTS

TRANS2 NOP BRCLR SC0SR1,#$80,TRANS2

MOVB 1,Y+,SC0DRL CPY #$0B16 BNE TRANS2

RTS

;;;;;;;;;;;;;;;;;;;;;;; ;Display the answer; ;;;;;;;;;;;;;;;;;;;;;;; ORG $0B00

COMMENT FCC 'THE result IS' ;location ended at $0B0Ddddd FCB $20 ;location ended at $0B0F ;FCC 'PLEASE SHOW RESULT' ;location ended at $B21 ;FCB $0D,$0A ;location ended at $B23 ;EOT FCB $04 ;location ended at $0B10 ;DISPLAY THE NUMBER, LOCATION AT $0905;

READING RMB 2 FCB $41 FCB $0D,$0A ;DATA FCC 'NEXT LENGTH' ; FCB $0D,$0A ;EOT2 FCB $04

Jessie

Reply to
Jessie

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.