/*
* nuart.c
*
* Created on: Mar 12, 2019
* Author: ndt
*/
#include "nuart.h"
uint8_t TxBuffer[50];
uint8_t RxBuffer[50];
__IO uint8_t TxCounter = 0x00;
__IO uint8_t RxCounter = 0x00;
uint8_t NbrOfDataToTransfer = 50;
uint8_t NbrOfDataToRead = 50;
void NUart_Init(){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
// Configure GPIO for USART1
Gpio_Uart_Configure();
// NVIC configure
USARTx_NVIC_Configure();
USART_InitTypeDef uart;
uart.USART_BaudRate = 9600;
uart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
uart.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
uart.USART_Parity = USART_Parity_No;
uart.USART_StopBits = USART_StopBits_1;
uart.USART_WordLength = USART_WordLength_8b;
USART_Init(USARTx,&uart);
//USART_ITConfig(USARTx,USART_IT_TXE,ENABLE);
USART_ITConfig(USARTx,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
void Gpio_Uart_Configure(){
GPIO_InitTypeDef io;
RCC_APB2PeriphClockCmd(USARTx_GPIO_CLK,ENABLE);
io.GPIO_Pin = USARTx_RxPin;
io.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(USARTx_GPIO,&io);
io.GPIO_Pin = USARTx_TxPin;
io.GPIO_Mode = GPIO_Mode_AF_PP;
io.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(USARTx_GPIO,&io);
}
void USARTx_NVIC_Configure(){
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Enable the USARTy Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void Usart_Send(uint8_t *c, uint8_t len){
while(len--)
{
USART_SendData(USART1,*c);
c++;
}
}
Paste Hosted With By Yam Code