cancel
Showing results for 
Search instead for 
Did you mean: 

USART not working

sue
Associate III
Posted on August 16, 2010 at 02:07

USART not working

24 REPLIES 24
sue
Associate III
Posted on May 17, 2011 at 14:02

Hi Clive, thanks again for your help.

I have set the USART prescaler to 1 RCC_CFGR is zeroed and that is why receive is now working.

But send is not.  Can you offer any other suggestions re send?

Posted on May 17, 2011 at 14:02

>>Looking at your original post, you do not appear to enable the clock for USART1.

Using USART2 this would not appear to be a problem.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 14:02

Hard to say, make sure you are enabling receive/transmit modes of all the USARTs

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
John F.
Senior
Posted on May 17, 2011 at 14:02

Looking at your original post, you do not appear to enable the clock for USART1. You really ought to learn C. It's not difficult!

John F.
Senior
Posted on May 17, 2011 at 14:02

I'm not sure any of us know what she's doing. I was going by, ''for all three usarts the receive is working (using usart2) (yeehaaa) but send is not (using usart1).  Is there anything different I have to do for send?'' (above).

Posted on May 17, 2011 at 14:02

The following should be a relatively minimal initiation of

USART1,2,3 at 9600 baud from the STM32 reset state.

;*****************************************************************************

; USART1 PA.9  TX, PA.10 RX

; USART2 PA.2  TX, PA.3  RX

; USART3 PB.10 TX, PB.11 RX

;*****************************************************************************

InitSystem    PROC

        ; Enter from reset routine, STM32 in initial state, clocking from HSI at 8 MHz

        ldr    r0, =0x40021000    ; RCC

        ldr    r1, =0x0000400C    ; USART1EN | IOPBEN (GPIOB) | IOPAEN (GPIOA)

        str    r1, [r0, #24]    ; +24 RCC_APB2ENR

        ldr    r1, =0x00060000    ; USART3EN | USART2EN

        str    r1, [r0, #28]    ; +28 RCC_APB1ENR

        ldr    r0, =0x40010800    ; GPIOA

        ldr    r1, =0x444444B4    ; PA.9 USART1_TX 50MHz AF_PP

        str    r1, [r0, #4]    ; +4  GPIOx_CRH

        ldr    r1, =0x44444B44    ; PA.2 USART2_TX 50MHz AF_PP

        str    r1, [r0, #0]    ; +0  GPIOx_CRL

        ldr    r0, =0x40010C00    ; GPIOB

        ldr    r1, =0x44444B44    ; PB.10 USART3_TX 50MHz AF_PP

        str    r1, [r0, #4]    ; +4  GPIOx_CRH

        ldr    r0, =0x40013800    ; UART1

        bl    InitUART

        ldr    r0, =0x40004400    ; UART2

        bl    InitUART

        ldr    r0, =0x40004800    ; UART3

        bl    InitUART

        bx    lr

        ENDP

;*****************************************************************************

InitUART    PROC

        ; R0 is base address of USART

        movs    r1, #0

        strh    r1, [r0, #4]    ;  +4 USART_DR

        movs    r1, #833    ; 8MHz / 833 == 9600

        strh    r1, [r0, #8]    ;  +8 USART_BR

        movs    r1, #0x0600

        strh    r1, [r0, #16]    ; +16 USART_CR2 = 0x600

        movs    r1, #0

        strh    r1, [r0, #16]    ; +16 USART_CR2 = 0

        movs    r1, #0

        strh    r1, [r0, #24]    ; +24 USART_GTPR = 0 - Prescaler

        movw    r1, #0x200C    ; 8-bit, no parity, enable TX,TX

        strh    r1, [r0, #12]    ; +12 USART_CR1

        ldr    r2, =10        ; 10 Pounds

iu1        ldr.w    r1, [r0, #0]    ; +0  USART->SR

        ands    r1, #0x80    ; TXE

        beq    iu1

        mov    r1, #'#'

        str.w    r1, [r0, #4]    ; +4  USART->DR

        subs.w    r2, r2,    #1    ; r2--

        bne.n    iu1

        bx    lr

        ENDP

;*****************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sue
Associate III
Posted on May 17, 2011 at 14:02

Hi John, thanks for your post.

In my original post, I was not using USART1, only USART2, and only trying to receive.

Having got receive working I am now trying to get send to work, and am using USART1 for that, although I have now added code to use USART2 alternatively.  Of course I have added code to enable everything that has to be enabled for USART1 and USART2 in order to send but I'm not going to post it unless invited to do so as it is now quite large.

No point in learning C as we cannot use it in production, it has to be assembler.

Posted on May 17, 2011 at 14:02

There are different prescalers, the fast ones in the RCC unit reset to DIV-BY-1 the internal system and bus clocks.

There is *another* unrelated prescaler in the USART, it relates to the Guard Time for the Smartcard mode, we are NOT using that. It should zero at reset, I simply have code that gets it too that state. Probably overkill.

The CR2 stuff is derived from some other ST code, and toggles the sync-clock bits, again probably overkill.

Once you get the code working as you want you could probably prune it back.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sue
Associate III
Posted on May 17, 2011 at 14:02

Hi Clive, thanks again for taking the trouble to post.

I am sure everyone, including me, is heartily sick of this topic.

I have only the following questions, Clive, about the assembler code you just posted (after that I'll leave you all alone):

1. why do you set USART_CR2 to 0x600 and then immediately clear it to zero?

2. why are you setting the prescalers to zero when in your earlier post you said they have to be set to 1? (and indeed I can see in the reference manual that this is what they have to be set to) 

Posted on May 17, 2011 at 14:02

>>No point in learning C as we cannot use it in production, it has to be assembler.

Some kind of defence/automotive/medical type thing, or you just work with luddites?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..