Question
STM32 USART DR unavailable
Posted on March 14, 2013 at 09:35
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