Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

DEPARTAMENTO DE ENGENHARIA ELÉTRICA

Lucca Favero Barbosa


Leonardo Oliveira Santos
Enzo Gullo Cantarin

USART 2 e USART 3

RELATÓRIO

Londrina
2024
1.
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;

// initializes USART1, USART2 e USART3


USART_Init(USART1, &USART_InitStructure);
USART_Init(USART2, &USART_InitStructure);
USART_Init(USART3, &USART_InitStructure);

// USART1, USART2 e USART3 enable


USART_Cmd(USART1, ENABLE);
USART_Cmd(USART2, ENABLE);
USART_Cmd(USART3, ENABLE);

/* Enable the USART Receive interrupt: this interrupt is generated


when the USART receive data register is not empty */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

2.
3.
4.
int PWM = 0;

void rxCom(u8 rxData)


{
// guardo o caractere recebido no vetor RxVector
RxVector[contRx] = rxData;

// timeout de 400 ms para zerar o pacote de dados recebidos


zerarPacote = 400;

/* vou armazenar somente 5 BYTES


* RxVector[0] = 0x00 (INIT Byte)
* RxVector[1] = 0x01 ==> LED 1 ON
* RxVector[2] = 0x01 ==> LED 2 ON
* RxVector[3] ==> 0x00 => 0%, 0x64 => 100% ==> PWM DC Channel 2 Timer
4
* RxVector[4] = 0xFF (END Byte)*/

/*if(RxVector[0] != 0x00 || RxVector[4] != 0xFF)


{
contRx = 0;
}*/

if(RxVector[0] != 0x00 && RxVector[4] != 0xFF )


{
contRx = 0;
}
else if (++contRx > 4)
{
contRx = 0;

switch(RxVector[1])
{
case 0x01:
GPIO_WriteBit(GPIOD, GPIO_Pin_14,SET);
break;
default: GPIO_WriteBit(GPIOD, GPIO_Pin_14,RESET);
}

switch(RxVector[2])
{
case 0x01:
GPIO_WriteBit(GPIOD, GPIO_Pin_15,SET);
break;
default: GPIO_WriteBit(GPIOD, GPIO_Pin_15,RESET);
}

if(RxVector[3] <= 0x64)


{
PWM = RxVector[3]*420;
TIM_SetCompare1(TIM4, PWM);

}
else if(RxVector > 0x64)
{
PWM = 420*0x63;
TIM_SetCompare1(TIM4, PWM);
}
else if(RxVector < 0x00)
{
PWM = 0;
TIM_SetCompare1(TIM4, PWM);
}

pacoteRecebido = 1;

You might also like