cancel
Showing results for 
Search instead for 
Did you mean: 

stm32F105rb usart

darekfilip
Associate II
Posted on April 22, 2014 at 10:50

Hi,

i have problems with usart communication with other cpu. I use stm32f150rb, UART4. My code:


RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);


GPIO_InitTypeDef gpioInit;

// rx = PC11

gpioInit.GPIO_Speed = GPIO_Speed_2MHz;

gpioInit.GPIO_Mode = GPIO_Mode_IN_FLOATING;

gpioInit.GPIO_Pin = GPIO_Pin_11;

GPIO_Init(GPIOC, &gpioInit);


// tx = PC10

gpioInit.GPIO_Speed = GPIO_Speed_2MHz;

gpioInit.GPIO_Mode = GPIO_Mode_AF_PP;

gpioInit.GPIO_Pin = GPIO_Pin_10;

GPIO_Init(GPIOC, &gpioInit);


/* Configure the NVIC Preemption Priority Bits */

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0 );


/* Enable the USARTy Interrupt */

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);


USART_DeInit(UART4 );

USART_InitTypeDef usartInit;

usartInit.USART_BaudRate = 9600;

usartInit.USART_WordLength = USART_WordLength_8b;

usartInit.USART_StopBits = USART_StopBits_1;

usartInit.USART_Parity = USART_Parity_No ;

usartInit.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

usartInit.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_Init(UART4, &usartInit);

USART_Cmd(UART4, ENABLE);


USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);


void UART4_IRQHandler() {

uint16_t rec = USART_ReceiveData(UART4 );

reciv_arr[receiv++] = rec & 0xFF;

if (receiv == 100 || reciv_arr[receiv - 1] == '\r'

|| reciv_arr[receiv - 1] == '\n') {

receiv = 0;

}

}


void send(char* buffer, int len) {

int i = 0;

for (; i < len; ++i) {

while (USART_GetFlagStatus(UART4, USART_FLAG_TXE ) == RESET)

;

USART_SendData(UART4, buffer[i]);

}

}

Sending looks ok - TXE is changing. RX cpu pin is connected to GND with 5k6 resistor if this matters. RX interrupt is never called. Does the init code looks ok? #selective-cut-n-paste
1 REPLY 1
Posted on April 22, 2014 at 16:32

Using C++? Check for name mangling, review .MAP file.

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