How to do hello world program

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

How to do hello world program

Jump to solution
4,423 Views
kamalesh
Contributor I

Hello Team,
I am new to this LPC microcontrollers. So, I have lpc11e36 microcontroller and trying to do hello world program which is i want to send the string through uart. I struggled lot. Is there any sample program for this particular microcontroller for uart.

Based on that uart dirver of lpc11xx series, I wrote one program. that is also not working.

I await for your response guys!!!.

Best Regards,
Kamalesh.C

Labels (2)
0 Kudos
Reply
1 Solution
3,313 Views
frank_m
Senior Contributor III

Sorry, but without having such an MCU or a board, there is not much I can do myself.

However, what I would check:
The peripheral pins require appropriate initialisation, i.e. enabling the port & pin, and switch it to the correct peripheral mode (I2C in this case). In the LPCXpresso SDK, this is done in a file called pin_mux.c. Check those are correct for your MCU and your board, cross-referencing with the datasheet (port/pin assignment).
For test purposes, you could also initialize it to standard push/pull GPIO, and toggle it in your code. That should be visible on a scope.
Second, check the board schematics the pin is really usable for this purpose, and not blocked by other attached components.
And third, check schematics and the physical board that a pull-up resistor is present on both I2C pins. Without such a pull-up resistor, you cannot measure a signal on an open-drain output.

View solution in original post

0 Kudos
Reply
22 Replies
4,200 Views
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hello,

 

Hope you are doing well. I would recommend checking the LPCOpen Libraries and Examples | NXP Semiconductors

For LPC11xx, please refer to LPCOpen Software for LPC11XX | NXP Semiconductors

You can check the available examples, to see if this can help you with your implementation on your MCU.

 

Best Regards,

Ricardo

0 Kudos
Reply
4,179 Views
kamalesh
Contributor I

Hi Ricardo,

I already gone through those examples, that examples for other series which is LPC11U series. I am using flash magic to upload. I compiled one of the lpcopen example program which is periph-uart. After build, It created .axf file. I changed this axf into hex file using some converter and flashed using flashmagic.

During flashing, It showing error. I could not use that exact examples of periph-uart also.

I am stucking in this area. Could you please give any suggestions or tutorials to clear this uart program for this particular lpc11e36 microcontroller.

Best Regards,
kamalesh

0 Kudos
Reply
4,219 Views
frank_m
Senior Contributor III

There is no need to figure everything out for yourself.
Although I have no LPC11xx MCU or board, so I use the one available to me as example.

First, create/download a SDK for your MCU and host OS. This process is well documented, I think.
Then, load this SDK with MCUXpresso, AFAIK by just dropping the file into the IDE Quickstart window.

Then, import an example from said SDK, as seen here :

frank_m_0-1707827365900.png

For the SDK I used, there is a "Hello World" in the demo_apps, as seen here:

frank_m_1-1707827473178.png

It should compile and build fine.
If you have a SDK for a specific board, it should run without any additional work or modification.

And I would start from there with modifications.

0 Kudos
Reply
4,215 Views
kamalesh
Contributor I

Hi Frank,

Thank you for the rapid reply.
But, MCUExpresso IDE is not having this LPC11E36 microcontroller examples. Especially, I need to send any string through uart.

Below program only I used, 

/*
===============================================================================
Name : uart_testing.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC11Exx.h"
#endif


#include <cr_section_macros.h>

int main(void) {


Chip_UART_Init(LPC_USART0);
Chip_UART_SetBaudFDR(LPC_USART0, 9600); // Set baud rate to 9600

// Send "Hello, World!" message using UART
const char *helloWorldMsg = "Hello, World!\r\n";


while (1) {
Chip_UART_Send(LPC_USART0, helloWorldMsg, strlen(helloWorldMsg));
}

return 0;
}

But, It returning error like LPC_USART0 undeclared.
Linking is not happening also coming.
Is there way to do other than this lpcexpresso ide?. This ide have lot of confusion.

Best Regards,
kamalesh

0 Kudos
Reply
4,213 Views
frank_m
Senior Contributor III

> But, MCUExpresso IDE is not having this LPC11E36 microcontroller examples. Especially, I need to send any string through uart.

You would need to create one yourself, from an NXP website.
Check out the following link (which requires a login) :
https://mcuxpresso.nxp.com/en/welcome

 

0 Kudos
Reply
4,210 Views
kamalesh
Contributor I

Hello Frank,

I tried this SDK creation. But This microcontroller series itself is not there. I uploaded a picture for your reference.

Regards,
kamaleshScreenshot (7).png

0 Kudos
Reply
4,208 Views
kamalesh
Contributor I
I am scared because of this. Is this possible to do? There is no such available libraries and lpcopen examples for this series lpc11exx.
0 Kudos
Reply
4,171 Views
frank_m
Senior Contributor III

Now that you say it ...
I didn't realize that the LPC11xx family is already so "old", and not directly supported by the SDK generator. But I had similiar experiences with LPC14xx and LPC17xx devices.

I would follow the recommendations of poster Ricardo_Zamora, and try the links to LPCOpen libraries and examples.

But if you deal with a project here that can be considered "commercial" in any way, I would rethink my choice of MCU. In my experience, it usually doesn't take long from fading toolchain support until the EOL notice is disseminated.
For hobbyist projects this is less of an issue, though.

0 Kudos
Reply
4,024 Views
kamalesh
Contributor I

Hello frank,

Sorry for the late reply.

Actually, we have the boards with this microcontroller. So , we have the situation to program for this microcontroller. That's why we are creating this thread.

Is there any other way to achieve this thing?. 

Best Regards,
kamalesh.C


0 Kudos
Reply
3,996 Views
frank_m
Senior Contributor III

I would say, you are bound to the legacy LPCOpen package for this MCU, as poster Ricardo_Zamora had pointed out.
Since he is NXP support staff, he can surely assist you with getting started.
I don't have real experience with this package.


And of course there is always the option of using just the MCU datasheet/manual, startup files, and MCU headers of your toolchain, and do everything else on your own.
Which is not recommended for beginner level. But occasionally this is the way to go, if your toolchain is not directly supported by the vendor. I did this for STM32Cxx parts not so long ago.

0 Kudos
Reply
3,697 Views
kamalesh
Contributor I

Hello Ricardo_zamora and Frank,

Sorry for the late reply.

I successfully achieved the hello world program through uart in lpc11e36 microcontroller.

Now, We are one step forwarded. I am trying to do the lcd program. My lcd is connected with i2c expander of PCA9546AD(channel -1). I2c from lpc11e36 microcontroller connected with this i2c expander.

I written one program to send hello world string to this lcd from this microcontroller. I attached the code given below. After executing the program, it is stucked. I found the place also. But I dont know why it is stopped in this place. Screenshot (14).png 
During the execution time of this line Chip_I2C_MasterSend(I2C0, I2C_LCD_ADDRESS, data, 2);,it could not processing this line.
In this above picture, I marked the line which I got a struck. Could you please clarify my doubts and verify my uploaded program?

Best Regards,
Kamalesh.C

0 Kudos
Reply
3,693 Views
frank_m
Senior Contributor III

Not having a LPC11e63 board or LCD display / I2C expander, I cannot say much about this issue.

But I would attach a logic analyser (or scope) to the I2C lines, and check the actual bus signals against the expected (i.e. the datasheet of the display/expander).

> During the execution time of this line Chip_I2C_MasterSend(I2C0, I2C_LCD_ADDRESS, data, 2);,it could not processing this line.

I would suspect the event this code waits for is an ACK from the slave.
Perhaps the I2C address is not correct.

0 Kudos
Reply
3,691 Views
kamalesh
Contributor I

Hello Frank,

Thank you for your rapid reply.

Actually, I checked with manufacturer of display for this physical address. This is the exact physical address.

Is my program structure was right?

If physical address is right in the since, what may be the reason for this struck?
I doubted on,
Mainly, I2C communication is not happening because of wrong connection or something else.

how to check the i2c communication? Is there any program to verify the i2c communication.

Regards,
Kamalesh.C

0 Kudos
Reply
3,685 Views
frank_m
Senior Contributor III

> how to check the i2c communication? Is there any program to verify the i2c communication.

By physically attach a logic analyser or a oscilloscope.
I did that for my private projects with simple and cheap USB 8-bit logic analyser pods, and the "PulseView" application (I use Linux for that purpose, but it runs on Windows, too).

> Actually, I checked with manufacturer of display for this physical address. This is the exact physical address.

You need to read the datasheet of your device carefully for that purpose.
The I2C device address is only 7 bits, the eights bit (LSB) defines read/write access.
Some manufacturers imply a left-shift of this 7-bit address value in their datasheet, others imply an 8-bit address with the R/W bit "OR-ed" in.
If the DS of your device is not really clear, the easiest way is to try both variants.
Some I2C devices have additional external "address pins", so as to operate more than one device on a single I2C bus. If this applies your device, check the required conditions (pull-up/pull-down) are met.

In general, getting such low-level busses like I2C or SPI are almost impossible to get to work without being able to check and evaluate the actual bus signals.

0 Kudos
Reply
3,666 Views
kamalesh
Contributor I

Hello frank,

Actually I tried your suggested way physical address also, but based on my program structure, it is strucked on CHIP_I2CTRANSFER function only.

I tried another example which is test the i2c communication of our board. In this program, I written some data in EEPROM of one address. For this write operation, I used this chip_i2c_transfer function. after this write operation, i have to use the read operation to read the data from the same address whichever I written in EEPROM. After Executing the transfer function in this i2c, It is stucked on i2c_event_wait. I uploaded a photo given below.

Also I found some forum related to my problem. I given the link below. They gave some software fix. How about my case?

https://community.nxp.com/t5/LPC-Microcontrollers/LPC4367-I2C-stuck-in-interrupt-handler/m-p/827339

Screenshot (17).png

Till this printing of BEFORE_WAIT_EVENT is happening, after this not happening. I want to know what is the reason. 

Here, I only given a random address and doing those operations(read and write). 

Is there any issue in my i2c communication?

Could you please tell me, why it is happening here?

For your reference, I attached my recent tested file.

Regards,
Kamalesh.C

0 Kudos
Reply
3,617 Views
frank_m
Senior Contributor III

> Also I found some forum related to my problem. I given the link below. They gave some software fix. How about my case?

To be honest, I don't know if this issue is related to your case.
This is a different MCU, and the I2C peripheral might be a different IP, with a different register interface.

I would start with consulting the I2C bus specification, and then try to monitor/record the actual bus signals in your case.
Many I2C slave devices, especially more complex ones like an LCD interface, define special requirements (usually for multi-byte transfers). You would need to compare the code and the observed signal with the requirements of your slave device.
I2C code for an IO expander or an EEPROM will not directly work with e.g. an I2C ADC or LCD device, you need to modify it.

0 Kudos
Reply
3,576 Views
kamalesh
Contributor I

Hello Frank,

I checked the I2c pins of LPC11e36 microcontroller with the oscilloscope.

For both the pins, It is getting high but there is no clock signals as well as other signals also. I don't know how to modify code according to this. You have any ideas about this?

In my uploaded code, I made a setup of clock frequency to 100khz. It should generate clock signals right?

Or Is there any mistake in my code?

Could you please check once and tell me?

For your reference, i2c frequency initialize program line given below.

#define I2C_FREQUENCY 100000


void I2C_Init(void) {
// Initialize I2C with the specified frequency
Chip_I2C_Init(I2C0);
Chip_I2C_SetClockRate(I2C0, I2C_FREQUENCY);
Chip_I2C_SetMasterEventHandler(I2C0, Chip_I2C_EventHandlerPolling);
}

These all the three processes are happening well. I don't know why it is not generating signal?

Regards,
Kamalesh.


0 Kudos
Reply
3,519 Views
frank_m
Senior Contributor III

>  You have any ideas about this?

Without a board like yours or even the MCU, I can nothing but guess. Perhaps the NXP staff members can help you better in this regard.

But two things you can check.
First, pull-up resistors are essential for I2C bus functionality. Without those, the bus does not work, and you see no signals. Check they are present/populated, and in a range of (usually) 1 kOhm ... 5 kOhm.
Internal pull-ups are most often insufficient.

Second, check the GPIO pins are properly initialized as I2C-peripheral.
MCUXpresso SDK examples for your MCU (or LPCOpen for older MCUs) can be used as reference here.

0 Kudos
Reply
3,467 Views
kamalesh
Contributor I

Hello Frank,

Second, check the GPIO pins are properly initialized as I2C-peripheral.

Actually I searched for the lpcopen examples of lpc11e3x microcontroller series. But there is no examples for this.

Can I use the examples of lpc11e6x series examples for this i2c gpio pin checking?

Regards,
Kamalesh

0 Kudos
Reply
3,336 Views
frank_m
Senior Contributor III

> Can I use the examples of lpc11e6x series examples for this i2c gpio pin checking?

I suppose yes.
Vendors tend to implement identical peripheral IP blocks on a wide variety of MCUs, if the requirements are similiar. Often even across different architectures.
Of course you will probably need to adapt the actual pins used.

0 Kudos
Reply