How to enable SCLK in SSP1 in SPI mode

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

How to enable SCLK in SSP1 in SPI mode

1,396 Views
marcosfg
Contributor I

Hello,

I am using gcc to develop firmware for a LPC43xx chip. I need to use the SSP1 peripheral to read a temperature from a MAX31855 thermocouple converter.

Basically I need to:

   - Pull the CS line down

   - Wait and read the output from the MAX31855

I have successfully programmed the chip to use the SSP0 channel, however when I try to use the SSP1 channel no clock is generated in the pin PF_4.

If I write any value to the DR register from the SSP1 it is written to the MOSI pin (P1_4), however no clock is generated.

Here's my configuration:

LPC_CGU->BASE_CLK[CLK_BASE_SSP1] = (1 << 11) | (CLKIN_MAINPLL << 24); //enable SSP1 clock

LPC_SCU->SPFP1_4 = 0xF5; //set P1_4 as function 5 (SSP1_MOSI), EPD=0, EPUN=1,EZI=1,ZIF=1, EHS = 1

LPC_SCU->SPFP1_3 = 0xF5; //set P1_3 as function 5 (SSP1_MISO), EPD=0, EPUN=1,EZI=1,ZIF=1, EHS = 1

LPC_SCU->SPFPF_4 = 0xF0; //set PF_4 as function 0 (SSP1_CLK), EPD=0, EPUN=1,EZI=1,ZIF=1, EHS = 1

LPC_SSP1>CR0 = 0x650F;   //SPI Mode, 16bit, SPOL=0, CPHA=0, SCR = 0x65
LPC_SSP1>CR1 = 0; //Master Mode

LPC_SSP1>CPSR = 2; // prescaler

LPC_SSP1>CR1 |= (1<<1); //Enable SSP1

After running this code, if I write a value to the LPC_SSP1->DR register I can see the output in MOSI pin, however no clock is generated. Similar config in the SSP0 works. Any help?

Labels (3)
0 Kudos
2 Replies

799 Views
michaelschuehle
Contributor II

Hello,

I think I have the same problem with the SSP1 clock. I'm using the LPC4357 OEM Board with the dev kit from embedded artists and work with the lpcOpen_2.09.
I can also measure the MOSI signals but have problems with the SCK signal. After some measurements I found the SCK signal with a very low amplitude of ~60mV. So I think there are no problems within the code. After that I isolated the SCK signal from the dev kit and measured the signal direkt at the LPC4357 the signal was then ~0,5V thats mor but definitely not enought to drive the bus.

@marco gomes: Could you solve your problem?

Are there any ideas what could be the problem?

0 Kudos

799 Views
dimitrissideris
Contributor III

Hi there,

I ve been struggling with spi myself so i have a basic understanding.

I am not quit sure what are you asking. If I am getting it wrong please reply and be more specific.

First of all i2c is more straight forward and "suitable" for sensor reading. I think its the best practice, but let's focus on spi.

1. Use LPCOpen examples for ssp (Are you using them?)

LPCOpen Software for LPC43XX|NXP 

2. Inside main function there is a Board_SSP_Init funtion.

This function uses the Chip_SCU_PinMuxSet function to set spi pins.

3. According to datasheet (what model of dev board do u have?) you can do sth like this

The below code is from lpcopen ssp example for 4367 dev board.

if (pSSP == LPC_SSP1) {

        Chip_SCU_PinMuxSet(0x1, 5, (SCU_PINIO_FAST | SCU_MODE_FUNC5));  /* P1.5 => SSEL1 */
        Chip_SCU_PinMuxSet(0xF, 4, (SCU_PINIO_FAST | SCU_MODE_FUNC0));  /* PF.4 => SCK1 */

        Chip_SCU_PinMuxSet(0x1, 4, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5)); /* P1.4 => MOSI1 */
        Chip_SCU_PinMuxSet(0x1, 3, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5)); /* P1.3 => MISO1 */

    }

So when i wanted to initialize and set SSP0 i added

else if (pSSP == LPC_SSP0) {

        Chip_SCU_PinMuxSet(0x1, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC5));
        Chip_SCU_PinMuxSet(0x3, 0, (SCU_PINIO_FAST | SCU_MODE_FUNC4));

        Chip_SCU_PinMuxSet(0x1, 2, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5));
        Chip_SCU_PinMuxSet(0x1, 1, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC5));

The above code and the lpcopen example is configured to auto toggle the cs line every sent frame. If you want a different functionality of chip select you should assign chip select to gpio pins so that you can manually manipulate them.

Ive tried both and worked.

You are welcome for any further details.

The below link is my feedback on how manual gpio chip select works

SSEL as Gpio for SSP/SPI 

0 Kudos