SPI lpc43xx always return 0

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

SPI lpc43xx always return 0

694 Views
lpcware
NXP Employee
NXP Employee
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);
  }
}
Labels (1)
0 Kudos
3 Replies

534 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mihirshah on Fri Apr 04 21:47:48 MST 2014
hey Sphoenix,

the thing that max responds with 0x02 do you mean that you are reading the ctrl1 reg .

I am facing issues in interfacing max11200 with 8051 controller.
Right now i am just reading the ctrl1 reg.
The waveforms on din and sclk pin of max11200 seems to be ok but the dout pin of max gives no response.
Can you guide if any other initialization is required.
The data i am sending on din pin is 0xc3 for reading ctrl1 reg.
I am using bit biting for SPI communication.
Awaiting your valued help.
Regards,
Mihir
0 Kudos

534 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Sphoenix on Thu Sep 05 04:10:28 MST 2013
Oh yeah that's works ! Thanks man !

I don't have your function but i set it manually in the register like this :

void init_protocol()
{
  LPC_SPI->CR = SPI_CR_MSTR_Msk;
  LPC_SPI->CCR = 128;

  LPC_SCU->SFSP3_6 = 1 | (1 << SCU_SFSP3_3_EZI_Pos); // MISO <= The line who save the day !
  LPC_SCU->SFSP3_7 = 1; // MOSI
  LPC_SCU->SFSP3_3 = 1; // SCK
  LPC_SCU->SFSP3_8 = 4; // SSEL
  LPC_GPIO_PORT->DIR[5] |= (1UL << 11) | 0;
}

Best Regards,
Sylvain
0 Kudos

534 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Thu Sep 05 02:21:16 MST 2013
Hello Sphoenix,
have a look at page 289 of user manual of lPC4357 (V1.6 - 25 Jan 2013).
In the middle there is a gate (right from glitch filter), which control input.
I had the problem with UART, but i think same with SPI.
There is a line from top called EZI, which i think must be set.
This bit is located in LPC_SCU->SFSPx_y (look at bit 6 EZI).
Perhaps look into example code, if additional bits must be set in this register.

For UART (!) i used
scu_pinmux(0xF ,10 , MD_PDN, FUNC1);            // PF.10 : UART0_TXD
scu_pinmux(0xF ,11 , MD_PLN|MD_EZI|MD_ZI, FUNC1);  // PF.11 : UART0_RXD

Best regards,
Martin

0 Kudos