LPC 2138 getting started - Page 1
Forum section: electronics / general

author: Boschi
author_rank: Regular Contributor
timestamp: June 05, 2017, 02:02:27 pm
content: hi, as i said in the title i need help to start programming a LPC2138 based board.if anyone has already programmed an LPC21xx board, which IDE did you use?so far i have seen LPCXpresso and ARMKeil, both have a forum and both seems to have some default library, which is important for an ARM newbie.for my applications i probably just need to use a UART, read some data with MODbus over rs485 and toggle some relay.im stepping here after some low level arduino programming, so what are the key features of ARM architectures?how much can i expect from IDE's library? like i have to implement everything or what?any text thats wort reading before starting? basically i have 0 experience in ARM programming, feel free to suggest anything!thanks for the reply and sorry for my bad english

author: rstofer
author_rank: Super Contributor
timestamp: June 05, 2017, 09:22:58 pm
content: I haven't programmed my LPC2148 in several years so memory fades. I remember using Rowley CrossWorks and Eclipse/GNUARM. both worked well but CrossWorks is more polished.Yes, you pretty much have to write everything, there is no build-in library code for the peripherals. Not to worry, everything that can be done has been done:http://www.jcwren.com/arm/The big difference between the LPC2138 and the LPC2148 is the USB support in the LPC2148.There's no hand-holding for these devices. There are no Arduino-like libraries. You're on your own!You will need to come up with a way to program the chip. Serial port programming works well but doesn't provide debugging. Use a lot of printf()s. If you use Rowley, they have a very nice JTAG dongle that does both programming and debugging. Highly recommended.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: June 05, 2017, 09:27:01 pm
content: If you have a choice, you're much better off with an ARM Cortex-M based board rather than an old LPC2xxx board.If you're doing this to gain experience with ARM, then Cortex-M is the way to go, not obsolete ARM7TDMI parts like the LPC2138.

author: legacy
author_rank: Super Contributor
timestamp: June 07, 2017, 08:12:41 am
content: I am still in business with LPC21xx, still used for panels facing the driver of a boat, as well as cruise ship, or the pilot of an small aircraft (class D), containing instruments and controls. uVision v5 as development sw, uLinkPro as hw debugger, as ucOS/2 as RTOS, which comes with specific drivers and applications.Now you can find ucOS/3 reloaded for Cortex. But it's more complex, and the chip itself is more complex.My customers are slowly moving to Cortex, soon or later I will have to.

author: Jeroen3
author_rank: Super Contributor
timestamp: June 07, 2017, 09:12:38 am
content: The LPC2138 is a bad start imho. Get some parts with a Cortex family core and you will be much more comfortable.It's a bad start because the LPC21 uses ARMv4 architecture, compared to Cortex which use ARMv6 which has improved a lot and has much better support in beginners embedded market.If you want to stay with NXP, get an LPC17 or LPC15.Also note that LPC2138 is from 2006, and has passed the 10 year mark. It will be EOL in 2021.

author: nctnico
author_rank: Super Contributor
timestamp: June 07, 2017, 05:22:36 pm
content: Then again a lot of knowledge gained from the LPC2138 can be used on the LPC17xx devices too because the peripherals are very similar (UART, SPI, I2C, timers, ADC are all backwards compatible).

author: Boschi
author_rank: Regular Contributor
timestamp: June 09, 2017, 02:20:05 pm
content: Unfortunately its not my choice, but its the boss one.for my first job ever its toughbasically its a industrial grade board, already certified for whatever it has to be.isthisa good starting point?

author: nctnico
author_rank: Super Contributor
timestamp: June 09, 2017, 04:02:54 pm
content: I scrolled through the PDF quickly. It seems to cover a lot of items. I'd try to find the projects (sourcecode) which come with it so you can build on those and don't have to mess with things like setting up the clock and startup code.

author: Boschi
author_rank: Regular Contributor
timestamp: June 09, 2017, 04:15:17 pm
content: i have alreadyfound themjust one question, what changes exactly from one IDE to another? in my school career i have used just codeblocks and netbeans, the mayor difference between them was the autocomplete feature

author: nctnico
author_rank: Super Contributor
timestamp: June 09, 2017, 04:25:27 pm
content: Mainly the editor and the ability to debug. You should be able to get Eclipse and a debugger going from a tutorial. I like Eclipse because it has a good editor and features to help go through sourcecode (like showing a function when you hover over the name, a list with variables and functions in the file you are editing, etc, etc). You can also do without a debugger but you'll need other tools like a console to print debug information and perhaps a command line interpreter with commands to show status information, look into memory addresses etc. One important thing to remember is to never develop a complex algorithm on a microcontroller. Always develop & test on a PC first and then insert it into your microcontroller project.

author: Boschi
author_rank: Regular Contributor
timestamp: June 28, 2017, 03:40:04 pm
content: im back!i have finally managed to upload something on the board (for now is just a pin blinking...), while i try to map the pin, do you have any suggestion about RTOS?the lpc2138 has a dedicated oscillator just for a RTC (page 219 of thedatasheet) and a number of register just for it.since im not doing critical timing stuff, how bad would be to fill a object with a stack of things to do and associate a "timestamp"to it, generate an interrupt on every change of second, minute hours or whatever, compare the current timestamp to the one stored in the object and if they coincide do everything stored in the stack?this is my first attempt to use/create an RTOS (even if simple and whitout a scheduler), what im missing? it would be harder than what im expecting? also, any trap for the young players?

author: rstofer
author_rank: Super Contributor
timestamp: June 28, 2017, 04:35:29 pm
content: Quote from: Boschi on June 28, 2017, 03:40:04 pmEarlier, I gave you a link towww.jcwren.com/armwhich has demo code that includes every bit of peripheral code you will ever need and also implements FreeRTOS which is pretty much the standard RTOS being used today.Omit everything having to do with USB when using the LPC2138.

author: Jeroen3
author_rank: Super Contributor
timestamp: June 28, 2017, 05:21:09 pm
content: If your application is not too big, simple multitasking using interrupts can work.Otherwise, you might use freertos or chibios.

author: legacy
author_rank: Super Contributor
timestamp: June 30, 2017, 05:25:45 pm
content: Four years ago project, but I remember that ucOS/2 worked very good a on tiny LPC2138-node.

author: Boschi
author_rank: Regular Contributor
timestamp: July 01, 2017, 11:20:07 am
content: How much it cost the ucOS/2? I wont do many project with it, also im just a student ( its a summer job) and before buy anything i want to be shure that is what i need and that im able to use itInviato dal mio A0001 utilizzando Tapatalk

author: Jeroen3
author_rank: Super Contributor
timestamp: July 01, 2017, 11:57:06 am
content: Software licenses use triple zero numbers. Use "open" version instead:ChibiOSorFreeRTOS.

author: Boschi
author_rank: Regular Contributor
timestamp: July 05, 2017, 10:15:30 am
content: thanks, but after digging a bit i think that just using interrupt can work.im losing myself in a glass of waterat the end i dont need multitasking, and i can just use the rtc to track the time, and do everything else in a loop, polling for the right time, or something similar. i'll see once i have something else working.i just realised that i need modbus rtu for communication, and it should be one of the first thing that i should implement.i know a little about it, the main thing is that it use rs485 as a "interface", so it should use a normal UART port, right?and because i have a FIFO queue in the Uc UART i can fill it for the first byte, then read it, and do all the decode necessary.feel free to suggest everything, im really a newbye and i need some advice to clear all the mess in my mind

author: Jeroen3
author_rank: Super Contributor
timestamp: July 05, 2017, 10:46:47 am
content: Using a real time operating system is not mandatory. You can perfectly use the idle loop (main) to poll a few things, and use prioritized interrupts to react to events. ARM has nesting so you can preempt other interrupts. Much like an RTOS would on events.Example (low priority first):Idle loop processes modbus request, blink some LED's and reset the watchdog.DMA interrupt processes ADC buffering complete and performs calculations.UART interrupt buffers and filters modbus frames.Timer interrupt to perform regular important things, such as a PID loop and outputs that need to be set on time based on values.GPIO interrupt react to emergency conditions.Systick updates system time and checks for stack anomalies or other runtime issues.You might benefit from using a library for modbus, you can buy them, or maybe you can find suitable open source projects.

author: Boschi
author_rank: Regular Contributor
timestamp: July 05, 2017, 03:41:31 pm
content: Quote from: Jeroen3 on July 05, 2017, 10:46:47 amthis sound intresting, once i am able to make modbus work ill shurely watch it closely.until then...i found a port of freemodbus for the LPC2148 (downloadhere)but in order to compile i need all the header in the "include" directory, plus a "port.h" file, which i have found (here) but i feel like is wrong, what should i look for?

author: alm
author_rank: Super Contributor
timestamp: July 05, 2017, 03:54:48 pm
content: Yes, that file would not work at all. Try the files from the demo/LPC214X/port directory.

author: rstofer
author_rank: Super Contributor
timestamp: July 05, 2017, 04:23:57 pm
content: One feature of the RS485 bus is that it is multi-master and, as a result, there can be collisions. When a collision is detected, both senders back off for some random amount of time and try again.The collision is detected by having the UART listen to what it is sending. If there is a mismatch, there is a collision. The thing is, FIFO UARTs might make this more difficult.Even in the single-master environment, we can have collisions if a slave decides to respond while the master is talking to a different slave. How long to wait for a missing slave to respond? Generally, RS485 runs half-duplex with all units sending and receiving on a single pair.Overall, RS485 can't be treated as a simple level shifter. The protocol itself can be a bit awkward when multiple masters are involved.It is likely that the MODBUS libraries will address these issues. Or not...

author: Boschi
author_rank: Regular Contributor
timestamp: July 06, 2017, 09:19:49 am
content: Quote from: alm on July 05, 2017, 03:54:48 pmi should probably check more carefully next time...anyway.... port.h file need another file, called "inttypes.h", wich should define some type of variables i think, this time i checked pretty carefully over all the directory and i didnt found it.as before, i found it on the web but im pretty shure is the wrong one, what should i look for?Quote from: rstofer on July 05, 2017, 04:23:57 pmi hope so, otherwise it will be a PITA to make everything work with non custom devicesA bit OT question, its possible to "extract" the SDK from lpcxpresso and use it in other IDE?because thanks to my school i have access to the full edition of Visual Studio which its way better than the NXP editor

author: alm
author_rank: Super Contributor
timestamp: July 06, 2017, 01:30:51 pm
content: inttypes.h is C99. That suggests that the example was made for a different compiler. Either try using the original compiler used for the port (according the the Changelog the LPC214x port was developed for Keil), see if your current compiler can enable C99 support or change the code to use the functionality that is available in your compiler (maybe define your own header). If you are new to this, then I would start with the original compiler. Keil is free up to 32 kB. Not sure if there is a time-limited trial available for with higher limits.Generally downloading random header files that may have been made for different compilers and systems is not going to work. It might be possible to get the header from Boost to work in this case. Assuming that is the only thing you are missing.

author: Boschi
author_rank: Regular Contributor
timestamp: July 07, 2017, 09:45:13 am
content: maybe i found something.i attached a inttypes.h coming from "...\LPCXpresso_8.2.2_650\lpcxpresso\tools\arm-none-eabi\include"it should work, right?just one thing is not clear to me, to be fully C99 compatible i should verify that newlib.h has been build C99 compatible, but how?i have also attached the newlib.h, the only time that talk of C99 is in the row 16 but i cant tell if its right or not.

author: alm
author_rank: Super Contributor
timestamp: July 07, 2017, 03:17:39 pm
content: Are you sure you are using Newlib and not the default Redlib? Newlib should have inttypes.h. A quick test project failed to build when I included inttypes.h until Iswitched from Redlib to Newlib.If the code uses C99 compiler features, then you may also have to select ISO C99 or GNU C99 under MCU C Compiler Dialect.