cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with USART3 and Systick

arielivandiaz
Associate
Posted on November 22, 2014 at 07:04

I can't send information using USART3 when I use the SysTick.I don't know what i can do to fix.

/* Includes ------------------------------------------------------------------*/
#include ''stm32f4xx_gpio.h''
#include ''stm32f4xx_rcc.h''
#include ''stm32f4xx_usart.h''
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
/**************************************************************************************/
void
RCC_Configuration(
void
)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
}
/**************************************************************************************/
void
GPIO_Configuration(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
}
/**************************************************************************************/
void
USART3_Configuration(
void
)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- Two Stop Bit
- Odd parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
void
send_data(uint16_t n, 
char
*arr){
uint16_t i=0;
while
(i<n){
while
(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET){} 
// Espera que el registro de transmision este libre
USART_SendData(USART3, arr[i]); 
// Envia un caracter
i++;
}
while
(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET){} 
// Espera que el registro de transmision este libre
USART_SendData(USART3, 
'\n'
); 
// Envia un caracter
while
(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET){} 
// Espera que el registro de transmision este libre
USART_SendData(USART3, 
'\r'
); 
// Envia un caracter
}
/**************************************************************************************/
int
main(
void
)
{
setvbuf
( stdout, 0, _IONBF, 0 );
RCC_Configuration();
GPIO_Configuration();
USART3_Configuration();
char
buff[50]={
'\b'
};
uint16_t Data_rec;
SysTick_Config((SystemCoreClock/3.125) / 1000000); 
//Here is the problem
while
(1)
{
sprintf
(buff,
'' %d,%d ''
, 88 ,55 );
send_data(7,buff); 
if
(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != RESET) 
// Si se encuentra un dato disponible lo leo con la siguiente línea
Data_rec = USART_ReceiveData(USART3); 
// Recibe un caracter
}
}

#stm32f4 #usart #systick
1 REPLY 1
Posted on November 22, 2014 at 14:10

I can't send information using USART3 when I use the SysTick. I don't know what i can do to fix.

So what does your SysTick interrupt code look like? When you're in the debugger, where does it end up? What does that suggest about the failure?
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..