Author Topic: LPC 2138 getting started  (Read 9481 times)

0 Members and 1 Guest are viewing this topic.

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
LPC 2138 getting started
« on: June 05, 2017, 02:02:27 pm »
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  ^-^
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 10094
  • Country: us
Re: LPC 2138 getting started
« Reply #1 on: June 05, 2017, 09:22:58 pm »
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.
« Last Edit: June 05, 2017, 11:26:50 pm by rstofer »
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1816
  • Country: us
Re: LPC 2138 getting started
« Reply #2 on: June 05, 2017, 09:27:01 pm »
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.
"That's not even wrong" -- Wolfgang Pauli
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: LPC 2138 getting started
« Reply #3 on: June 07, 2017, 08:12:41 am »
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.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4659
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: LPC 2138 getting started
« Reply #4 on: June 07, 2017, 09:12:38 am »
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.
« Last Edit: June 07, 2017, 09:14:16 am by Jeroen3 »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30434
  • Country: nl
    • NCT Developments
Re: LPC 2138 getting started
« Reply #5 on: June 07, 2017, 05:22:36 pm »
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).
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #6 on: June 09, 2017, 02:20:05 pm »
Unfortunately its not my choice, but its the boss one.
for my first job ever its tough  :-\

basically its a industrial grade board, already certified for whatever it has to be.

is this a good starting point?

 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30434
  • Country: nl
    • NCT Developments
Re: LPC 2138 getting started
« Reply #7 on: June 09, 2017, 04:02:54 pm »
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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #8 on: June 09, 2017, 04:15:17 pm »
i have already found them

just 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
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30434
  • Country: nl
    • NCT Developments
Re: LPC 2138 getting started
« Reply #9 on: June 09, 2017, 04:25:27 pm »
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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #10 on: June 28, 2017, 03:40:04 pm »
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 the datasheet) 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?

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 10094
  • Country: us
Re: LPC 2138 getting started
« Reply #11 on: June 28, 2017, 04:35:29 pm »
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?


Earlier, I gave you a link to www.jcwren.com/arm which 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.
« Last Edit: June 28, 2017, 04:37:51 pm by rstofer »
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4659
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: LPC 2138 getting started
« Reply #12 on: June 28, 2017, 05:21:09 pm »
If your application is not too big, simple multitasking using interrupts can work.
Otherwise, you might use freertos or chibios.
 

Offline legacy

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: LPC 2138 getting started
« Reply #13 on: June 30, 2017, 05:25:45 pm »
Four years ago project, but I remember that ucOS/2 worked very good a on tiny LPC2138-node. 
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #14 on: July 01, 2017, 11:20:07 am »
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 it

Inviato dal mio A0001 utilizzando Tapatalk

 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4659
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: LPC 2138 getting started
« Reply #15 on: July 01, 2017, 11:57:06 am »
Software licenses use triple zero numbers. Use "open" version instead: ChibiOS or FreeRTOS.
« Last Edit: July 01, 2017, 11:59:13 am by Jeroen3 »
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #16 on: July 05, 2017, 10:15:30 am »
thanks, but after digging a bit i think that just using interrupt can work.
im losing myself in a glass of water  |O

at 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
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4659
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: LPC 2138 getting started
« Reply #17 on: July 05, 2017, 10:46:47 am »
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.
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #18 on: July 05, 2017, 03:41:31 pm »
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.

this 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 (download here)

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?
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: LPC 2138 getting started
« Reply #19 on: July 05, 2017, 03:54:48 pm »
Yes, that file would not work at all ;). Try the files from the demo/LPC214X/port directory.

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 10094
  • Country: us
Re: LPC 2138 getting started
« Reply #20 on: July 05, 2017, 04:23:57 pm »
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...
 

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #21 on: July 06, 2017, 09:19:49 am »
Yes, that file would not work at all ;). Try the files from the demo/LPC214X/port directory.
:wtf: i 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?

...
It is likely that the MODBUS libraries will address these issues.  Or not...
i hope so, otherwise it will be a PITA to make everything work with non custom devices

A 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
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: LPC 2138 getting started
« Reply #22 on: July 06, 2017, 01:30:51 pm »
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.

Offline BoschiTopic starter

  • Regular Contributor
  • *
  • Posts: 88
  • Country: it
  • just a arduino-guy
Re: LPC 2138 getting started
« Reply #23 on: July 07, 2017, 09:45:13 am »
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.
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2903
  • Country: 00
Re: LPC 2138 getting started
« Reply #24 on: July 07, 2017, 03:17:39 pm »
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 I switched 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.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->