#define SMR_485TRANSMIT LPC_GPIO5->SET |= (1<<0) //CHANGE DATA FLOW TO TRANSMIT
#define SMR_485RECEIVE LPC_GPIO5->CLR |= (1<<0) //CHANGE DATA FLOW TO RECEIVE
int main(void) {
uart2();
NVIC_EnableIRQ(UART2_IRQn);
while(1) {
}
}
void receive(void) {
SMR_485RECEIVE;
delay_10_micro();
receive_byte = LPC_UART2->RBR;
}
void send(void) {
SMR_485TRANSMIT;
delay_1_ms();
LPC_UART2->THR = receive_byte;
}
void UART2_IRQHandler(void) {
BYTE maska = LPC_UART2->IIR & 0x04;
if(maska == 0x04){
receive();
delay_10_micro();
send();
delay_10_micro();
}
}
|
void uart2(void){
LPC_SC->PCONP |= (1<<24); // power to the uart2 peripheral
LPC_UART2->LCR = 0x83; // 8 bits, parity none, stopbit 1, DLAB ENABLED
LPC_UART2->FCR = 7; // FIFO enable, Rx FIFO reset, Tx FIFO reset
LPC_UART2->FCR = 1; // reset fifo
/* Then reset DLAB bit */
LPC_UART2->LCR = 0x03; // disable DLAB so that interrupts are enabled
LPC_UART2->IER = 0x03;
//pinsel for UART2
LPC_IOCON->P0_10 = 1; // UART2 TXD
LPC_IOCON->P0_11 = 1; // UART2 RXD
LPC_IOCON->P5_0 = 0; // SMR_485
LPC_GPIO5->DIR |= (1<<0);
}
|