2014-10-24 05:23 AM
Hey,
I am new to the ARM development coming from a background of 8051, PIC and some AVR. With my first new test I managed to make input and output work, also I have manage to direct EXTI on input pins. Now I am trying the USART on the STEVAL-IDB002V1 and so far I am hitting a dead end. No matter how many codes I have tried something is not write and the USART does not work. I might have been missing something, maybe someone here can direct me to it. I have connectec the STEVAL to an FTDI chip and I am trying to read the data from my pc, so far it is not working at all. The pins from the STEVAL J1.15 J1.17 Here is my full code, thanks for any help.#include ''stm32l1xx.h''
#include ''stm32l1xx_conf.h''
void InitializeUSART()
{
USART_InitTypeDef usartConfig;
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2 |
RCC_AHBPeriph_GPIOA , ENABLE);
USART_Cmd(USART2, ENABLE);
usartConfig.USART_BaudRate = 9600;
usartConfig.USART_WordLength = USART_WordLength_8b;
usartConfig.USART_StopBits = USART_StopBits_1;
usartConfig.USART_Parity = USART_Parity_No;
usartConfig.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
usartConfig.USART_HardwareFlowControl =
USART_HardwareFlowControl_None;
USART_Init(USART2, &usartConfig);
GPIO_InitTypeDef gpioConfig;
//PA2 = USART2.TX => Alternative Function Output
gpioConfig.GPIO_Mode = GPIO_Mode_AF;
gpioConfig.GPIO_Pin = GPIO_Pin_2;
gpioConfig.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &gpioConfig);
//PA3 = USART2.RX => Input
gpioConfig.GPIO_Mode = GPIO_Mode_AF;
gpioConfig.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &gpioConfig);
}
unsigned char USART_ReadByteSync(USART_TypeDef *USARTx)
{
while
((USARTx->SR & USART_SR_RXNE) == 0)
{
}
return
(unsigned char)USART_ReceiveData(USARTx);
}
int main()
{
InitializeUSART();
for
(;;)
{
USART_SendData(USART2, 0x56);
USART2->DR = (0x56 & (uint16_t)0x01FF);
// unsigned char byte = USART_ReadByteSync(USART2);
asm(
''nop''
);
}
}
#context-context-context
2014-10-24 05:31 AM
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2 |
RCC_AHBPeriph_GPIOA , ENABLE);
APB1 != APB2 != AHB
2014-10-24 06:01 AM
Wow that make me feel stupid hhehehhee.
Anyways I fixed the problem, I think .RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
and also changed the loop to
USART_SendData(USART2, 'c');
//Loop until the end of transmission while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET) { } Now something else is happening, on my PC I receive 0x00 once upon the initialization before hitting the loop. And after it I don't receive anything anymore.2014-10-24 08:09 AM
L1 USART2 Example half way down
If you want me to code for your board you'll need to send me one.2014-10-24 09:08 AM
Thanks for your help man.
I don't want you to make the code for me, I am just starting with ARM and I needed a push in the right direction. I cannot send you the ST board, but once I finalize my work you will be on the list of people to get one, that is if you are interested.Regards