Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] STM32F100RBT6B problem with usart

Status
Not open for further replies.

Anton2727

Newbie level 1
Joined
Jun 15, 2017
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
20
I have on radio transmitter and one radio receiver. What I am trying to do.
I send data through USART2 PA2 (pin2) on data transmitter.
I connected usb-uart to PA2 (pin2), and looked in terminal what data is there and I saw something like this (11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44 ).It's okay i transmit what i want.

Then i connected usb-uart to PA10 (pin10), and looked in terminal, there was a lot of data but mostly of them was (44 FD 11 22 33 44 7F 10 22 33 44 FE 11 22 33 44 00 00 00 A4 26 F4 F8 11 22 33 44 FE 11 22 33 44 FA 10 22 33 44 FF 11 22 33 44 FE 11 22 33 44 D6 11 22 33 44 ).It's okay i receive from receiver module data that was transmitted.

Then iconnected usb-uart to PA9 (pin9), and looked in terminal, there was only (11 33 44 FC 11 33 44 FF 10 33 44 FF 11 33 44 FE ).

When USART1 receiving data from transmitter(Pin10)(44 FD 11 22 33 44 7F 10 ) it receiving full sequence(11 22 33 44), but when it transmit to Pin9 i see only (11 33 44).

Where is one byte (22)? Where is error and why it's happening thanks!

The main question what I am doing wrong, why USART1 TX deformates data? How to fix this?


Code:
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"

#define SYNC 0xAA
#define RADDR 0x44
#define LEDON 0x11//switch led on command
#define LEDOFF 0x22//switch led off command

void Delay(uint32_t value)
{
	volatile uint32_t i;
	for (i = 0; i != value; i++)
		;
}
void send_to_uart1(uint8_t data)  
	{
	while(!(USART1->SR & USART_SR_TC))
	{
	}
	USART1->DR=data;				
}

void send_to_uart2(uint8_t data)
{
	while (!(USART2->SR & USART_SR_TXE));
	USART2->DR = data;
}

uint8_t GetChar (void)  {
  while (!(USART1->SR & USART_SR_RXNE));
  return ((USART1->DR));
}
uint8_t uart_data;

int k=0;

char message[4]={0x11,0x22,0x33,0x44};

	int main(void)
	{
		GPIO_InitTypeDef PORTA_init_struct;

		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
		RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

		PORTA_init_struct.GPIO_Pin = GPIO_Pin_9;
		PORTA_init_struct.GPIO_Speed = GPIO_Speed_2MHz;
		PORTA_init_struct.GPIO_Mode = GPIO_Mode_AF_PP;
		GPIO_Init(GPIOA, &PORTA_init_struct);

		PORTA_init_struct.GPIO_Pin = GPIO_Pin_10;
		PORTA_init_struct.GPIO_Speed = GPIO_Speed_2MHz;
		PORTA_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
		GPIO_Init(GPIOA, &PORTA_init_struct);

		PORTA_init_struct.GPIO_Pin = GPIO_Pin_2;
		PORTA_init_struct.GPIO_Speed = GPIO_Speed_2MHz;
		PORTA_init_struct.GPIO_Mode = GPIO_Mode_AF_PP;
		GPIO_Init(GPIOA, &PORTA_init_struct);

		PORTA_init_struct.GPIO_Pin = GPIO_Pin_3;
		PORTA_init_struct.GPIO_Speed = GPIO_Speed_2MHz;
		PORTA_init_struct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
		GPIO_Init(GPIOA, &PORTA_init_struct);

		USART_InitTypeDef uart_struct1;
		uart_struct1.USART_BaudRate = 1200;
		uart_struct1.USART_WordLength = USART_WordLength_8b;
		uart_struct1.USART_StopBits = USART_StopBits_1;
		uart_struct1.USART_Parity = USART_Parity_No;
		uart_struct1.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		uart_struct1.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
		USART_Init(USART1, &uart_struct1);
		USART_Cmd(USART1, ENABLE);

		USART_InitTypeDef uart_struct2;
		uart_struct2.USART_BaudRate = 1200;
		uart_struct2.USART_WordLength = USART_WordLength_8b;
		uart_struct2.USART_StopBits = USART_StopBits_1;
		uart_struct2.USART_Parity = USART_Parity_No;
		uart_struct2.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
		uart_struct2.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
		USART_Init(USART2, &uart_struct2);
		USART_Cmd(USART2, ENABLE);
					
		while (1) {
				while(k<4)
				{
					for (int j=0;j<4;j++)
					{
						send_to_uart2(message[k]);
						k=k+1;
					}
					for (int i=0;i<4;i++)
					{
						send_to_uart1(GetChar());
					}
			}
			k=0;
		}
	}
 
Last edited:

I'm not sure of the impact of this, but you could add a very small delay between each transmitted byte or alternatively set 2 stop bits on the transmitter's (TX) UART and 1 stop bit on the receiver's (RX) UART. It seems to me that the receiving system is failing to act on such a data stream overload.
 

I don't get it. If you have DMA, USART interrupt, why do you using pooling method? This is stupid arduino approach.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top