vikky
Full Member level 3
- Joined
- Oct 18, 2007
- Messages
- 150
- Helped
- 4
- Reputation
- 8
- Reaction score
- 3
- Trophy points
- 1,298
- Activity points
- 2,664
The baud rate is 9600.if you are receiving rubbish the probable cause it the baud rate of the transmitter and the receiver are different
what do you think the baud rate from the microcontroller is?
could you post the code?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 void UARTSend(uint32_t portNum, uint8_t *BufferPtr, uint32_t Length) { while ( Length != 0 ) { if ( portNum == 0 ) { /* THRE status, contain valid data */ #if !TX_INTERRUPT while ( !(LPC_UART0->LSR & LSR_THRE) ); LPC_UART0->THR = *BufferPtr; #else /* Below flag is set inside the interrupt handler when THRE occurs. */ while ( !(UARTTxEmpty0 & 0x01) ); LPC_UART0->THR = *BufferPtr; UARTTxEmpty0 = 0; /* not empty in the THR until it shifts out */ #endif } else { /* THRE status, contain valid data */ #if !TX_INTERRUPT while ( !(LPC_UART1->LSR & LSR_THRE) ); LPC_UART1->THR = *BufferPtr; #else /* Below flag is set inside the interrupt handler when THRE occurs. */ while ( !(UARTTxEmpty1 & 0x01) ); LPC_UART1->THR = *BufferPtr; UARTTxEmpty1 = 0; /* not empty in the THR until it shifts out */ #endif } BufferPtr++; Length--; } return; } void UARTInit(uint32_t portNum, uint32_t baudrate) { uint32_t i, Fdiv; uint32_t regVal; if ( portNum == 0 ) { UARTTxEmpty0 = 1; UARTCount0 = 0; for ( i = 0; i < BUFFSIZE; i++ ) { UARTBuffer0[i] = 0; } NVIC_DisableIRQ(UART0_IRQn); SetupUART_Location( portNum, 0 ); /* default is location 0 */ /* Enable UART 0 clock */ LPC_SYSCON->PRESETCTRL |= (0x1<<2); LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<12); LPC_SYSCON->UART0CLKDIV = 0x1; /* divided by 1 */ LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ regVal = LPC_SYSCON->UART0CLKDIV; Fdiv = ((SystemCoreClock/regVal)/16)/baudrate ; /*baud rate */ LPC_UART0->DLM = 0x00; LPC_UART0->DLL = 0x13; LPC_UART0->LCR = 0x03; /* DLAB = 0 */ LPC_UART0->FDR = 0x10; /* set to default value: 0x10 *///0x10 LPC_UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ /* Read to clear the line status. */ regVal = LPC_UART0->LSR; /* Ensure a clean start, no data in either TX or RX FIFO. */ while ( (LPC_UART0->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); while ( LPC_UART0->LSR & LSR_RDR ) { regVal = LPC_UART0->RBR; /* Dump data from RX FIFO */ } /* Enable the UART Interrupt */ NVIC_EnableIRQ(UART0_IRQn); #if TX_INTERRUPT LPC_UART0->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */ #else LPC_UART0->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */ #endif } else { UARTTxEmpty1 = 1; UARTCount1 = 0; for ( i = 0; i < BUFFSIZE; i++ ) { UARTBuffer1[i] = 0; } NVIC_DisableIRQ(UART1_IRQn); SetupUART_Location( portNum, 0 ); /* default is location 0 */ /* Enable UART 1 clock */ LPC_SYSCON->PRESETCTRL |= (0x1<<3); LPC_SYSCON->SYSAHBCLKCTRL |= (0x1<<13); LPC_SYSCON->UART1CLKDIV = 0x1; /* divided by 1 */ LPC_UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ regVal = LPC_SYSCON->UART1CLKDIV; Fdiv = ((SystemCoreClock/regVal)/12)/baudrate ; /*baud rate */ //LPC_UART1->DLM = Fdiv / 256; //LPC_UART1->DLL = Fdiv % 256; LPC_UART0->DLM = 0x00; //LPC_UART0->DLL = Fdiv % 256; LPC_UART0->DLL = 0x13; LPC_UART1->LCR = 0x03; /* DLAB = 0 */ LPC_UART1->FDR = 0x10; /* set to default value: 0x10 */ LPC_UART1->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ /* Read to clear the line status. */ regVal = LPC_UART1->LSR; /* Ensure a clean start, no data in either TX or RX FIFO. */ while ( (LPC_UART1->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) ); while ( LPC_UART1->LSR & LSR_RDR ) { regVal = LPC_UART1->RBR; /* Dump data from RX FIFO */ } /* Enable the UART Interrupt */ NVIC_EnableIRQ(UART1_IRQn); #if TX_INTERRUPT LPC_UART1->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */ #else LPC_UART1->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */ #endif } return; } int main (void) { SetupUART_Location(0,0); UARTInit(0,9600); while(1) { LPC_UART0->IER = IER_THRE | IER_RLS; UARTSend( 0, "K" , 1); LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR; } }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?