lpcware

SPI lpc43xx always return 0

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Sphoenix on Thu Sep 05 02:02:51 MST 2013
Hello,

I'm actually work with an lpc4357 and i try to set an spi communication with a MAX11200.
To put it simple, i already done a working code to communicate with on a arduino and now i tried to recode it on the lpc4357
The problem is can't read anything else than 0 on LPC_DR->SPI.
My MOSI and MISO line are good, the max respond 0x02(i checked with a scope) but DR is always at zero.
I tried to check SR but it says that everything is ok, and i also trid to connect MOSI and MISO to receive the data i send but still 0.

Could someone have a clue, please ?

Here my code for when i connect MOSI and MISO (build under crossworks):

#include <__cross_studio_io.h>
#ifndef CMSIS_BITPOSITIONS
#define CMSIS_BITPOSiTIONS
#endif
#include <lpc43xx.h>
#include "spi_func.h"

#define CS_LOW   LPC_GPIO_PORT->CLR[5] = (1<<11)
#define CS_HIGH  LPC_GPIO_PORT->SET[5] = (1<<11)

uint32_t spi_transfert(int data)
{
  uint32_t tmp;

  LPC_SPI->DR = data;
  while (!(LPC_SPI->INT & SPI_INT_SPIF_Msk))
  {
  };
  debug_printf("%d\n", LPC_SPI->SR);
  tmp = LPC_SPI->DR;
  return (tmp);
}

void init_protocol()
{
  LPC_SPI->CR = SPI_CR_MSTR_Msk | SPI_CR_SPIE_Msk;
  //debug_printf("%d\n", LPC_SPI->CR);
  LPC_SPI->CCR = 128;

  LPC_SCU->SFSP3_6 = 1; // MISO
  LPC_GPIO_PORT->DIR[0] &= ~(1<<6) | 0;
  LPC_SCU->SFSP3_7 = 1; // MOSI
  LPC_GPIO_PORT->DIR[5] |= (1UL << 10) | 0;
  LPC_SCU->SFSP3_3 = 1; // SCK
  LPC_SCU->SFSP3_8 = 4; // SSEL
  LPC_GPIO_PORT->DIR[5] |= (1UL<<11) | 0;

  NVIC_EnableIRQ(SPI_INT_IRQn);
}

void
main(void)
{
  uint32_t data;

  debug_printf("hello world\n");
  init_protocol();
  while (1)
  {
    CS_LOW;
    data = spi_transfert(0b11000011);
    CS_HIGH;
    debug_printf("status : %d, return %d\n", LPC_SPI->SR, data);
    delay(1000);
  }
}

Outcomes