We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Using a keil mcb2300 with lpc2378.
Used the NXP example bundle uart code as the base and attempting to modify it to use all four uarts via interrupts. Couldn't find any examples that use all four uarts on lpc2300.
zip of base project www.alexthegeek.com/.../testUsarti.zip code www.alexthegeek.com/.../
The uart init routines run and print out their message on uart0. uart0 and uart1 work and echo back characters when initalised in order 0,1,2,3 but not uart2 and 3.
Most likely I'm doing something dumb or missing something simple. Any hints or pointers appreciated.
Not sure on the pinsel settings as its been a while since I've used lpc2000's (mostly xilinx , avr and st32f lately)
Thank you
Alex
pinsel
/* PinSelect and Pinmode settings */ /* UART0 = COM1 DB9 P4 on mcb2300 */ /* UART1 = COM1 DB9 P3 on mcb2300 */ /* UART2 = COM 2 is on IDC (TXD2=P2.8 (93), RXD2=P2.9 (92), GND=GND (103) */ /* UART3 = COM3 is on IDC (TXD3 = P0.0 (66), RXD3 = P0.1 (67), GND=GND (42) */ PINSEL0 = 0x4000005A; /* binary: 01000000_00000000_00000000_01011010 */ PINMODE0 = 0x800000AA; /* binary: 10000000_00000000_00000000_10101010 */ // IO0DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL1 = 0x00000001; /* binary: 00000000_00000000_00000000_00000001 */ PINMODE1 = 0x0000000A; /* binary: 00000000_00000000_00000000_00001010 */ PINSEL2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINMODE2 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ // IO1DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL3 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINMODE3 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL4 = 0x000A0000; /* binary: 00000000_00001010_00000000_00000000 */ PINMODE4 = 0x000A0000; /* binary: 00000000_00001010_00000000_00000000 */ // PINSEL4 = 0x000A000A; // binary: 00000000_00001010_00000000_00001010 FIO2DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL6 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINMODE6 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ FIO3DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL7 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINMODE7 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL8 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINMODE8 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ FIO4DIR = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINSEL9 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */ PINMODE9 = 0x00000000; /* binary: 00000000_00000000_00000000_00000000 */
The binary comments are in so I could work out/see what each register is at.
I have PCONP selected and PCLKSEL 0 and 1 (PCLK = CLk/4) for uarts 0 ,1,2 and 3 in the configuration wizard (for lpc2300.s)
Do I need to set it in my code or will the setting in lpc2300.s do it ?
in lpc2300.s PCONP_Val EQU 0x0300039E
I'm not familiar with keil , been doing a lot of reading (docs and examples) but still trying to get my head around things.
not quite right in lpc2300.s values are PCLKSEL0_Val EQU 0x00000000 PCLKSEL1_Val EQU 0x00000000 PCONP_Val EQU 0x03000018
doh very dumb error forgot to check if the mcb2300 has rs232 levels on uart 2 and 3(idiot!) so need to add a max563 or st232 chip to convert to rs232 levels
But they still don't actually tell you that - do they?
You still have to go away and look them up separately.
What Per is saying is that it would be far more helpful if the comments showed what the bits actually mean.
Further, rather than have a laborious, manual, error-prone translation - wouldn't it be better to use symbolic names...?
Great when the defines for the symbolic names are correct. A right pain in the proverbial when you blindly trust them and find they're not!
It is quite often that the supplied header files only have register names. So I normally create my own constants for the individual bits/bit fields of the registers.
Next thing is that initialization of the port pins for an UART should not make direct writes to the configuration registers - the registers contains bits for many other pins that are likely to be used by other parts of the code. So it is way better to mask out and set only the bits that are relevant for the UART.
So for PCONP would set like PCONP |= ( 1<< 24); for each peripheral you need to enable
or just set it in the asm file ?
I think maintaining the manual hex-to-binary translations is likely to be a greater risk...
You can use the wizard that allows you to edit lots of these settings in the asm file.
Personally, I like to have specific code in the source file that uses the peripherial, so I get a complete code bundle that can be reused. And that can be activated/deactivated at runtime depending on needs.