Hi,
Based on your advice, I made the following test:
#include "mbed.h"
SPI spi(p11, p12, p13); // mosi, miso, sclk
int angle;
int main()
{
//LPC_SPI->SPCR = 0x0000003C;
//LPC_PINCON->PINSEL0 = 0xC0000000;
//LPC_PINCON->PINSEL1 = 0x0000003F;
//LPC_SPI->SPCCR = 0x00000008;
while(1)
{
spi.format(16,3);
angle = spi.write(0x8888);
wait_us(1);
}
}
When I check on the oscilloscope, I see what I expect on the following pins:
- pin 11 mosi, I can see 0x8888
- pin 13 sclk I can see the clock
But unfortunately, I can not find any chip select signal.
My guess is that there is something wrong with these lines:
LPC_PINCON->PINSEL0 = 0xC0000000;
LPC_PINCON->PINSEL1 = 0x0000003F;
This is my guess because when I put the line "LPC_PINCON->PINSEL0 = 0xC0000000;" as I comment and I "activate" the line "LPC_PINCON->PINSEL1 = 0x0000003F;", then I can see the clock on the oscilloscope (Port0.15, meaning pin 13).
When I do the opposite, meaning when I "activate" the line "LPC_PINCON->PINSEL0 = 0xC0000000;" and when I put the line "LPC_PINCON->PINSEL1 = 0x0000003F;" as a comment, then the pin 13 (clock) is blocked at high state" whereas I can see properly the mosi signal.
So I am sure that my problem is that I am not "activating" properly the port 0.16 (pin 14) as a chip select because I see all other signals but this signal does not work.
Any idea ?
Hello ! I am very beginner with the mbed and I would like to program a SPI communication between the MBED and my product. My problem is that I do not know how to set properly the different registers.
What I did is:
#include "mbed.h" int angle; int main() { // BitEnable=1, CPHA=1, CPOL=1, MSTR=1, LSBF=0, SPIE=0, BITS=0000 LPC_SPI->SPCR = 0x0000003C; //Function 3 for pin15 (SCK) LPC_PINCON->PINSEL0 = 0xC0000000; //Function 3 for pins 16,17,18 (SSEL,MISO,MOSI) LPC_PINCON->PINSEL1 = 0x0000003F; //Set clock frequency to a random value LPC_SPI->SPCCR = 0x00000008; while(1) { //Write the Data register to start a SPI transfer LPC_SPI->SPDR = 0xAAAAAAAA; } }When I compile it, I do not get any error but when I boot it on the MBED, the 4 LEDs are blinking and I do not see anything on the oscilloscope.
Could someone help me fixing this code ? The only thing I want to do is perform a SPI transfer with a SCK frequency of 20MHz.
My first idea was to use something like:
#include "mbed.h" SPI spi(p5, p6, p7); // mosi, miso, sclk DigitalOut cs(p8); int main() { spi.format(16,3); spi.frequency(25000000); cs=1; while(1) { cs = 0; spi.write(0x8888); cs = 1; } }But If I do like this then I obtain something like 1us delay between the chip select falling edge and the first clock rising edge. This is a delay I can not afford because my product is a 500kHz refresh rate sensor so I really need a fast SPI communication.
Thanks in advance to those who will be able to help me.
Regards, Sebastien