#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;
}
}