cancel
Showing results for 
Search instead for 
Did you mean: 

STEVAL-IDB002V1 USART Problem

hisham
Associate II
Posted on October 24, 2014 at 14:23

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
4 REPLIES 4
Posted on October 24, 2014 at 14:31

RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2 |
RCC_AHBPeriph_GPIOA , ENABLE);

APB1 != APB2 != AHB
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hisham
Associate II
Posted on October 24, 2014 at 15:01

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.
Posted on October 24, 2014 at 17:09

L1 USART2 Example half way down

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32L15x%20UART%20Configuration%20and%20use%20problem&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&...

If you want me to code for your board you'll need to send me one.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hisham
Associate II
Posted on October 24, 2014 at 18:08

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