2013-03-14 01:35 AM
Hey, guys!
I have one stupid error, show me the right way, please. I'm actually working with STM32L-Discovery and trying firstly to work out the USART. I've done all necessary configurations for the simpliest transmitter mode, but my RS232/USB receiver don't want to see any sygnal. I've ckecked everything and catch the bug by means of DEBUGGING (using Keil). I have seen that function USART_SendData (including address USART->DR) do nothing with DR register!! It is 0x0000 all the time.int main (void) {
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // GPIOA Clock Enable, AHB Bus, AHBENR Register
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); // GPIOB Clock Enable, AHB Bus, AHBENR Register
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); // GPIOC Clock Enable, AHB Bus, AHBENR Register
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE); // GPIOD Clock Enable, AHB Bus, AHBENR Register
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); // USART3 Clock Enable, APB1 Bus, APB1ENR Register
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); // I2C1 Clock Enable, APB1 Bus, APB1ENR Register
RCC_APB1PeriphClockCmd(RCC_APB1Periph_LCD, ENABLE); // LCD Clock Enable, APB1 Bus, APB1ENR Register
PWR_RTCAccessCmd(ENABLE);
RCC_LSICmd(ENABLE);
Delay(100);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
RCC_RTCCLKCmd(ENABLE);
/* PC10 for USART3 TX PC11 for USART3 RX */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_USART3);
/* USART3_InitStructure configuration */
USART3_InitStructure.USART_BaudRate = 9600;
USART3_InitStructure.USART_WordLength = USART_WordLength_8b;
USART3_InitStructure.USART_StopBits = USART_StopBits_1;
USART3_InitStructure.USART_Parity = USART_Parity_No ;
USART3_InitStructure.USART_Mode = USART_Mode_Tx;
USART3_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_DeInit(USART3);
USART_Init(USART3, &USART3_InitStructure);
USART_Cmd(USART3, ENABLE);
while (1)
{ // Loop forever
USART_SendData(USART3, 0x00FF);
Delay(500);
};
}
#stm32-usart-data-register
2013-03-14 02:05 AM
> I've ckecked everything and catch the bug by means of DEBUGGING (using Keil). I have
> seen that function USART_SendData (including address USART->DR) do nothing with > DR register!! It is 0x0000 all the time. Actually, you can't ''see'' the ''result'' of writing to the USART_DR register, as reading it back it does not return the value written to it, rather, it returns the Rx value. Refer to the manual: The Data register performs a double function (read and write) since it is composed of two registers, one for transmission (TDR) and one for reception (RDR) JW2013-03-14 02:17 AM
You're right, but i mean the DEGUB mode register monitoring and after operation USART_DataSend(USART3, Data) i must see in DR window data to outcome. Or maybe DEBUG operation with such double register is unpredictibile?
2013-03-14 03:16 AM
Don't be obsessed by how the debug stuff does or does not work. Your problem is not there.
JW2013-03-14 04:32 AM
The internal state of the peripheral is not totally visible, neither you nor the debugger can see inside. Reading DR will always show the Received data. The data you write will be staged in the transmit register, before being moved to the outbound shift register.
Want to see what's getting transmitted, get a scope, or attach a terminal. You should only send data when TXE signals. Spin on USART->SR & TXE When enabling RTC clocks, etc, you should wait of ready status, not insert arbitrary delays. Such delays will bite you when there are silicon/component variations.2013-03-14 09:49 AM
Also, when using the debugger to view registers I think I have seen times where a register that clears status flags with a read operation (read/clear by read (rc_r)) has cleared them on a debug read potentially leaving the program code waiting on a flag that's never set.
2013-03-17 11:10 AM
Thank you, everybody. Code is OK, the problem was in wiring.
Conclusion: DEBUGger really doesn't see USART->DR register.