Content originally posted in LPCWare by cwpjr on Fri May 17 15:27:17 MST 2013
I run a 12 year old xp system with 768mb of ram. Drive c: fits xp and windows installed programs only and barely has enough room to defrag.
Drive E: holds My Documents, the code red installation and all else.
Does this mean I can't get project help?
Anyway I tried to uploaded the modified uart.c from the uart example program (which I modified only UARTInit) and my project main.c which includes the UARTInit routine only. But those aren't valid attachment file extension.
so my projects main.c with modified UARTInit from the UART Example code, where this same code works in UART/Drivers/Uart.c but not when pasted into my main.c: (There must be some other initialization going on outside of the UARTInit routine in startup of the UART example code.)
#ifdef __USE_CMSIS
#include "LPC11xx.h"
#endif
#include <cr_section_macros.h>
#include <NXP/crp.h>
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
// TODO: insert other include files here
#include <Stdint.h>
// TODO: insert other definitions and declarations here
#include "LPC11xx.h"
#include "uart.h"
#include "system_LPC11xx.h"
void UARTInit(uint32_t baudrate)
{
uint32_t Fdiv;
uint32_t regVal;
// UARTTxEmpty = 1;
// UARTCount = 0;
// NVIC_DisableIRQ(UART_IRQn);
LPC_IOCON->PIO1_6 &= ~0x07; /* UART I/O config */
LPC_IOCON->PIO1_6 |= 0x01; /* UART RXD */
LPC_IOCON->PIO1_7 &= ~0x07;
LPC_IOCON->PIO1_7 |= 0x01; /* UART TXD */
/* Enable UART clock */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */
LPC_UART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
regVal = LPC_SYSCON->UARTCLKDIV;
// Fdiv = (((SystemCoreClock*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ; /*baud rate */
Fdiv = (((48000000*LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ; /*baud rate */
LPC_UART->DLM = Fdiv / 256;
LPC_UART->DLL = Fdiv % 256;
LPC_UART->LCR = 0x03; /* DLAB = 0 */
LPC_UART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
/* Read to clear the line status. */
regVal = LPC_UART->LSR;
/* Ensure a clean start, no data in either TX or RX FIFO. */
// CodeRed - added parentheses around comparison in operand of &
//>>LITERAL VALUES USED HERE BECAUSE\
//>>LSR_THRE, etc is in uart.h but somehow not seen<<<<<<<<
// while (( LPC_UART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
while (( LPC_UART->LSR & (0x20|0x40)) != (0x20|0x40) );
// while ( LPC_UART->LSR & LSR_RDR )
while ( LPC_UART->LSR & 0x01 )
{
regVal = LPC_UART->RBR; /* Dump data from RX FIFO */
}
/* Enable the UART Interrupt */
// NVIC_EnableIRQ(UART_IRQn);
//#if CONFIG_UART_ENABLE_INTERRUPT==1
//#if CONFIG_UART_ENABLE_TX_INTERRUPT==1
// LPC_UART->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART interrupt */
//#else
// LPC_UART->IER = IER_RBR | IER_RLS; /* Enable UART interrupt */
//#endif
//#endif
LPC_UART->THR = 'A';
regVal = LPC_UART->RBR;
return;
}
int c_64by32div ( int divisor, long long dividend )//int divmsw, int divlsb )
{
int rem = dividend % divisor; // rem = divmsw+divlsb % divisor;
int quo = dividend / divisor; // quo = divmsw+divlsb / divisor;
return (quo); // quo in t/x (r0/r3), rem in w (r2)
}
long long c_32by32to64mul (int a, int b)
{
long long res = a * b;
return (res); // LSW in x (r3), MSB in n (r1)
}
#define UART_BAUD 115200
int main(void) {
// TODO: insert code here
UARTInit(UART_BAUD);
// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;
while(1) {
FIG_COLD();
i++ ;
}
return 0 ;
}