#include "MKL25Z4.h"
#include "main.h"
#include "uart.h"
#include <stdarg.h>
void UART0_init (void)
{
SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;
SIM_SOPT2 |= SIM_SOPT2_UART0SRC(0x1) ;
SIM_SCGC5 |=SIM_SCGC5_PORTD_MASK;
PORTD_PCR6 = PORT_PCR_MUX(3);
PORTD_PCR7 = PORT_PCR_MUX(3);
// Disable UART0 before changing registers
//UART0_C2 &= ~(UART0_C2_TE_MASK | UART0_C2_RE_MASK);
/* configure uart1 for 8-bit mode , no parity */
//UART0_C1 = 0U;
/* calculate the sbr value. */
UART0_C4=0x03;
UART0_BDH = UART0_BDH_SBR(0x4e2>>8);
UART0_BDL = UART0_BDL_SBR(0x4e2);
/*UART0_C4 = 0x03; // baud rate = 19200 with 48MHz clock
UART0_BDL = 0xE8;
UART0_BDH = 0x03;*/
//UART0_C3 = 0U;
//UART0_S1 = 0x1FU;
//UART0_S2 = 0U;
/* enable the tx and rx */
//UART0_C2 |= (UART0_C2_TE_MASK | UART0_C2_RE_MASK);
}
void UART0_PutTxData(uint8_t txData)
{
UART0_D = txData;
}
bool UART0_IsTxBufferEmpty(void)
{
return ( 0U != (UART0_S1 & UART0_S1_TDRE_MASK) );
//return (UART0_S1&= ~UART0_S1_TDRE_MASK);
}
bool UART0_IsRxBufferFull(void)
{
return (0U != (UART0_S1 & UART0_S1_RDRF_MASK) );
//return (UART0_S1&= ~UART0_S1_RDRF_MASK);
}
/*void UART0_PutTxDataBlocking(uint8_t txData)
{
UART0_C2 |= UART0_C2_TE_MASK;
while (!UART0_IsTxBufferEmpty() ) {}
UART0_PutTxData(txData);
while (!UART0_IsRxBufferFull() ){
; // wait if transferring
}
UART0_D = (txData/256);
}*/
void UART0_PutTxDataBlocking(uint8_t txData)
{
while (!UART0_IsTxBufferEmpty() ) {}
UART0_PutTxData(txData);
}
/*uint8_t UART0_GetRxData(void)
{
//return (uint8_t)(UART0_D);
UART0_PutTxData(txdata);
UART0_D = (UART0_D/256);
return (uint8_t)(UART0_D);
}*/
uint8_t UART0_GetRxData(void)
{
return (uint8_t)(UART0_D);
}
uint8_t UART0_GetRxDataBlocking(void)
{
while (!UART0_IsRxBufferFull() ) {}
return UART0_GetRxData();
}
哪里错了 |