10 years, 1 month ago.

Using SPI on LPCXpresso11U68

Hi, I am trying to use the SPI interface on the LPCXpresso11U68.

I am using the mbed HAL APIs to init the spi interface.

I have used the following pins for spi_init(&spi, P0_9, P0_8, P1_29, NC);

and configuring the CS line as:

gpio_init(&gpio_pin_CS, P0_14); gpio_mode(&gpio_pin_CS, PullNone); gpio_dir(&gpio_pin_CS, PIN_OUTPUT); gpio_write(&gpio_pin_CS, 1);

But reading using spi_master_write(...) does not seem to work and I am not getting the expected return value (always returns 0).

My question is : Are all the SPI pins mentioned in the diagram correct and is my usage correct in the above?

Can anyone with experience on SPI on LPCXpresso11U68 please comment?

Thanks, mridu

Question relating to:

Hi,

First of all, you can use wiki marup syntax for your code snipet to be more readable. e.g. <<code>> and <</code>> http://developer.mbed.org/cookbook/Wiki-Syntax

Quote:

My question is : Are all the SPI pins mentioned in the diagram correct and is my usage correct in the above?

I can't understand why you are using spi_xxx and gpio_xxx functions directly instead of SPI or DigitalOut class members.

SPI spi(P0_9, P0_8, P1_29);
DigitalOut cs(P0_14);

void foo()
{
    cs = 0;
    spi.write(0);
    cs = 1;
}
posted by Toyomasa Watarai 12 Oct 2014

Thanks for your comment. Will keep that in mind. I would like to add that using Pin P0_2 as the CS line also does not work.

posted by Mridupawan Das 13 Oct 2014

Hi,

Could you send or publish your complete test code?

posted by Toyomasa Watarai 15 Oct 2014

Hi, let's say the code as simple as what you have written above. E.g.

SPI spi(P0_9, P0_8, P1_29);
DigitalOut cs(P0_14);
 
void foo()
{
    cs = 0;
    spi.write(0);
    cs = 1;
}

The problem seems to be that the CS line is not getting toggled by the writing to the clear and set register.

But when I set or clear a digital pin e.g. P1_28, the toggle is clearly visible.

SO the analog pins are not behaving as expected. But I cannot use any other pin since this is the expected CS line for the component attached to the LPCXpresso11U68.

Checking the GPIO Port Pin Registers gives status of 1 even after clearing the bit. Rest all configurations of the GPIO, IOCON and CLK registers seems fine to me at least.

posted by Mridupawan Das 15 Oct 2014

1 Answer

10 years ago.

Hi,

Quote:

SO the analog pins are not behaving as expected. But I cannot use any other pin since this is the expected CS line for the component attached to the LPCXpresso11U68.

That's true.

There were missing initialization for some analog pins (from A1 to A3) when they were used as DigitalOut or DigitalIn, because default mode of pin function is not GPIO. I fixed the issue and it was merged to mbed SDK master repo.

https://github.com/mbedmicro/mbed/commit/b0a7a246c147df566cdd270d77d0d1cfcf6205af

It will be available next library update.