cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F100 USART outputs 00

an
Associate II
Posted on November 27, 2013 at 15:56

Hi together,

I am using the code below to iterate over SRAM and put out every byte over USART1. However, I am receiving only null-bytes. I was debugging the codein Keil MDK and everything seems to be fine except that when putting the value to be transmitted into USART1->DR the register seems to keep value 00 and does not hold the actual value (see line 37). THE USART1 data register is at 0x400138 The code should be ok, maybe it is because of the wiring? I connected a FOCA break-out board to my STM32 (FOCA RX to PA9 STM, FOCA TX to PA10 STM, grnd to grnd, and vcc to 3.v STM). Thanks in advance!


ldr r0, =0x40021000 ; RCC


ldr r1, =0x00004004 ; USART1EN | IOPAEN (GPIOA)

str r1, [r0, #0x18] ; RCC_APB2ENR


ldr r0, =0x40010800 ; GPIOA


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

str r1, [r0, #4] ; GPIOx_CRH


ldr r0, =0x40013800 ; UART1


movs r1, #0

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


movs r1, #69 ; 8MHz / 69 == 115200

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, =0x2000 ; Size = Length (8K)

ldr r3, =0x20000000 ; Mem = RAM Address

iu1 ldrh r1, [r0, #0] ; USART->SR

ands r1, #0x80 ; TXE

beq iu1

ldrb r1, [r3], #1 ; [Mem++]

strh r1, [r0, #4] ; USART->DR

subs r2, r2, #1 ; Size--

bne iu1

#usart #stm32-usart-data-register #stm32
5 REPLIES 5
Posted on November 27, 2013 at 16:53

Looks familiar...

Try sending some other region of memory, like the ROM? Try sending a specific character?

How are you examining USARTx->DR, you understand there are two registers there, and you can't see the one you WRITE into.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
an
Associate II
Posted on November 28, 2013 at 12:49

This code used to work months ago. Now I wanted to reuse it again but it does not work anymore and I do not know what happened.

Sending a specific character: I uncommented line 4 and inserted the line below:

1.
iu1 ldrh r1, [r0, #0] ; USART->SR
2.

ands r1, #0x80 ; TXE
3.

beq iu1
4.

;ldrb r1, [r3], #1 ; uncommented

this

line
5.

mov r1, #0x64 ; Inserted

this

line
6.

strh r1, [r0, #4] ; USART->DR
7.

subs r2, r2, #1 ; Size--
8.

bne iu1

Sending something from ROM: I am reading from 0x08000000 into r1 and try to write it to the USART1 data register (see lines ).


iu1 ldrh r1, [r0, #0] ; USART->SR

ands r1, #0x80 ; TXE

beq iu1

;ldrb r1, [r3], #1 ; [Mem++]

ldr r1, =0x08000000 ; Mem = RAM Address

ldrb r1, [r3], #4 ;

strh r1, [r0, #4] ; USART->DR

subs r2, r2, #1 ; Size--

bne iu1

In both cases, I only receive 0x00 on the terminal. I know that inspecting the memory with the memory viewer wont show me the data I put in the register. However, using Keil, it is possible to examine the registers via view > system viewer > uart1
Posted on November 28, 2013 at 13:37

However, using Keil, it is possible to examine the registers via view > system viewer > uart1

But this doesn't have magic access, the value in USARTx->DR is for data received, not data being transmitted.

Test the USART function within the regular application, observe also the signal on a scope.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
an
Associate II
Posted on December 05, 2013 at 14:09

Hi cl1ve,

I finally found the problem: It was not because of the code but because of the usb-ttl-converter. It was broken, so it displayed the correct amount of bytes however only zero bytes. Coincidentally, a second converter was broken as well. This is why I assumed that this could not be the root of problems. After trying a third one, it showed that the code works perfectly fine.

Thanks again!

Posted on December 05, 2013 at 15:27

This is why I own a scope. Glad you tracked it down.

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