LPC1343 UART without CMSIS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1343 UART without CMSIS

3,167 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Sat Jul 28 22:03:34 MST 2012
I tried to code LPC1343 UART without using CMSIS. Without CMSIS, the device runs at 12MHz. I took this into account by setting SystemFrequency = 12000000 but I still cant get it to work.UART does not send or receive at any baud rate.
0 Kudos
Reply
20 Replies

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Aug 08 08:51:43 MST 2012

Quote:

uint32_t* pointer = 0x10000000 //Assuming an unused ram location

Why assuming? MAP file can clarify that

#1 LPCXpresso is a C Compiler, so pointer should work

#2 There's a debugger included, so you can select 'pointer', right Click and use 'Add Watch Expression...' to show it in Expressions View  :eek:

#3 There's semihosting included, so semihosting projects can answer your question:

int main(void)
{
 printf("Hello World\n");
 volatile static int i = 0 ;
 uint32_t* pointer = (uint32_t*)0x10000200;
 *pointer=100;
 printf("Question: What is stored in  %X ?\n",pointer);
 printf("Answer: Surprise, it's %d !\n",*pointer);
 ....
#4 Memory View can monitor your address, just use 'Add Memory Monitor' and while stepping through your code this View is showing what's happening 
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Wed Aug 08 05:20:12 MST 2012
Is it possible to do this...

uint32_t* pointer = 0x10000000 //Assuming an unused ram location

*pointer=100;

or something like...

if(*pointer==100)   ...;

Can I explicitly write out RAM memory addresses
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Wed Aug 08 05:15:48 MST 2012
Okay, Ill start afresh incorporating all the changes I am told to make as per this thread. Thanks Zero for looking into the problem...
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Aug 08 02:03:13 MST 2012
This UARTInit is just a copy of an UARTInit with which millions of other users are working out here. So what should be wrong with it?

You've deleted NVIC_EnableIRQ() and added
/* Enable the UART Interrupt */
ISER1|=1<<14;
which is a clueless approach to this register and should be:
//enable UART Interrupt
ISER1 = 1<<14; //Writing 0 has no effect, writing 1 enables the interrupt
But that's not the problem. This UARTInit is doing everything necessary to work with UART.

The problem is that
[INDENT] #1 you don't use a valid baudrate

#2 you don't use a valid transmit function

#3 you don't use a valid interrupt handler
[/INDENT]I've mentioned all this things last week :eek: , but obviously you are not trying to solve this :rolleyes:

Reading UART functions from samples could solve this in 30 minutes and generate a working UART
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Tue Aug 07 21:33:33 MST 2012
GPIO works perfectly without the CMSIS headers. Infact, I managed to do a little motor speed control program with the 1343 without using CMSIS. What special initializations does the UART require?? From what I have read, SystemInit() sets the clock to 72MHz. The manual says that the 12MHz RC oscillator ticks by default if SystemInit() is not used and I have set SystemFrequency to 12000000 to abide by that rule. What am I missing out in the UARTInit() function???
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Aug 05 06:25:44 MST 2012

Quote: paganborn25
I still cannot get it to work. Does the SystemInit() function have something to do with this???


SystemInit() is used by CMSIS, you've decided not to use it  ;)

Do you remember:

Quote:
I tried to code LPC1343 UART without using CMSIS.

Your problem is that you are still working clueless with UART :)
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sun Aug 05 01:15:21 MST 2012
And did you write to UART as Zero suggested :confused:
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Sat Aug 04 19:37:28 MST 2012
I still cannot get it to work. Does the SystemInit() function have something to do with this???
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Aug 01 21:14:49 MST 2012
#1 Before you try to read via interrupt, write data to UART and check your serial hardware. If you can receive this data anywhere, your UART settings are correct.

#2 Write a valid UART interrupt code. There's a sample included which shows you what has to be done (=read) to get a working ISR.
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Wed Aug 01 17:49:49 MST 2012
I enabled the IOCON register but it still does not work. I also have the cr_startup_lpc13.c included in my workspace, it is only the CMSIS libraries that are excluded.
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Aug 01 09:47:14 MST 2012
Enable IOCON in SYSAHBCLKCTRL before accessing IOCON registers.
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Wed Aug 01 09:23:41 MST 2012
The UART does not work even at 110bps. Could I get some help with the actual startup initialization code (I want to write it from scratch). I am using the XPresso IDE. 

Also, I could not find any startup code references in the 1343 manual. Everything seems to be initialized to a fixed default value on reset...
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Jul 31 22:09:27 MST 2012

Quote:

Fdiv = (((SystemFrequency/SYSAHBCLKDIV)/regVal)/16)/baudrate ; /*baud rate */



You are trying to generate a 115200 UART with 12MHz :eek:

Did you calculate how accurate this is :confused:
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Tue Jul 31 19:15:21 MST 2012
Here's the code. The UART interrupt triggers on reset (???) and never again no matter how many times I send serial data. Trying to blink an LED once serial data is received. Is there a mistake in assuming the clock default as 12MHz??? Do I need to configure SYSREMAP to RAM??? Or is there some assembly code I need to write before this...

//Code
#include "stdint.h"

#define __PTR *(volatile uint32_t*)

#define ISER1 __PTR 0xE000E104
#define ICER1 __PTR 0xE000E184
#define SYSAHBCLKCTRL __PTR 0x40048080
#define SYSAHBCLKDIV __PTR 0x40048078
#define U0IER __PTR 0x40008004
#define U0RBR __PTR 0x40008000
#define U0THR __PTR 0x40008000
#define U0IIR __PTR 0x40008008     //Some places in the manual suggest             //40048008.
#define U0FCR __PTR 0x40008008
#define U0LSR __PTR 0x40008014
#define U0LCR __PTR 0x4000800C
#define GPIO0DIR __PTR 0x50008000
#define GPIO0DATA __PTR 0x50003FFC
#define U0DLL __PTR 0x40008000
#define U0DLM __PTR 0x40008004
#define IOCON_PIO1_6 __PTR 0x400440A4
#define IOCON_PIO1_7 __PTR 0x400440A8
#define UARTCLKDIV __PTR 0x40048098

#define SystemFrequency 12000000   //The default RC oscillator is 12MHz

#define IER_RBR        0x01
#define IER_THRE    0x02
#define IER_RLS        0x04

#define IIR_PEND    0x01
#define IIR_RLS        0x03
#define IIR_RDA        0x02
#define IIR_CTI        0x06
#define IIR_THRE    0x01

#define LSR_RDR        0x01
#define LSR_OE        0x02
#define LSR_PE        0x04
#define LSR_FE        0x08
#define LSR_BI        0x10
#define LSR_THRE    0x20
#define LSR_TEMT    0x40
#define LSR_RXFE    0x80

#define BUFSIZE        0x40

void UARTInit(uint32_t Baudrate);
void UART_IRQHandler(void);
void UARTSend(uint8_t *BufferPtr, uint32_t Length);
void blink_led(void);

void UART_IRQHandler(void)
{
  blink_led();
}

void UARTInit(uint32_t baudrate)
{
  //The default RC oscillator is used at 12MHz
  uint32_t Fdiv;
  uint32_t regVal;

  ICER1|=1<<14;

  IOCON_PIO1_6 &= ~0x07;    /*  UART I/O config */
  IOCON_PIO1_6 |= 0x01;     /* UART RXD */
  IOCON_PIO1_7 &= ~0x07;
  IOCON_PIO1_7 |= 0x01;     /* UART TXD */
  /* Enable UART clock */
  SYSAHBCLKCTRL |= (1<<12);
  UARTCLKDIV = 0x1;     /* divided by 1 */

  U0LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */
  regVal = UARTCLKDIV;
  Fdiv = (((SystemFrequency/SYSAHBCLKDIV)/regVal)/16)/baudrate ;    /*baud rate */

  U0DLM = Fdiv / 256;
  U0DLL = Fdiv % 256;
  U0LCR = 0x03;        /* DLAB = 0 */
  U0FCR = 0x07;        /* Enable and reset TX and RX FIFO. */

  /* Read to clear the line status. */
  regVal = U0LSR;

  while (( U0LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
  while ( U0LSR & LSR_RDR )
  {
    regVal = U0RBR;    /* Dump data from RX FIFO */
  }

  /* Enable the UART Interrupt */
  ISER1|=1<<14;

  U0IER = IER_RBR | IER_RLS;    /* Enable UART receive interrupt */

  return;
}

void blink_led()
{
    int i;
    i=U0IIR;
    i=U0LSR;
    i=U0RBR;
    SYSAHBCLKCTRL|=1<<6;
    GPIO0DIR|=1<<7;
    GPIO0DATA&=~1<<7;
    for(i=0;i<350000;i++);
    GPIO0DATA|=1<<7;
    return;
}

int main (void)
{
      UARTInit(115200);
      while(1);
}
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Tue Jul 31 12:47:14 MST 2012
Hi paganborn25,

please check 'www.lpcware.com' and see:

http://www.lpcware.com/content/nxpfile/sample-code-bundle-lpc1311134243-peripherals-using-keils-mdk-...
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Mon Jul 30 22:57:30 MST 2012

Quote: paganborn25
Yes, I configured all the clocks according to the manual. Doesnt it take the default values if you don't????...:confused:


What default values?

Show us the code that doesn't work and we might be able to tell you what is wrong with it.
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Mon Jul 30 20:22:31 MST 2012
What does the BYPASS bit in the SYSOSCCTRL  register exactly do. Does the LPC1343 have another internal (Low Power)  oscillator apart from WDT and IRC, or is this merely a buffer selection  for the external oscillator...?
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Mon Jul 30 20:20:22 MST 2012
I am writing an RTOS for LPC1343. Could any one offer any suggestions regarding that... Thanks...
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by paganborn25 on Mon Jul 30 20:18:02 MST 2012
Yes, I configured all the clocks according to the manual. Doesnt it take the default values if you don't????...:confused:
0 Kudos
Reply

3,097 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Jul 28 23:30:17 MST 2012

Quote:
I tried to code LPC1343 UART without using CMSIS.

Is there a special reason for that? Without knowing Cortex basics you should avoid that :eek:


Quote:
I took this into account by setting SystemFrequency = 12000000 but I still cant get it to work.UART does not send or receive at any baud rate.

That's not enough. If you don't use CMSIS you have to setup things like SYSAHBCLKCTRL yourself. Did you do that?
0 Kudos
Reply