AnsweredAssumed Answered

TWRADCDAC-LTC in MQX 4.0

Question asked by Sebastian Irimia on May 11, 2013
Latest reply on May 17, 2013 by Martin Latal

Hi everyone,

 

 

I need to read from TWRADCDAC-LTC from a K60F120M board, and I am doing it via spi0. I have a working setup with MQX 3.8, and now I am trying to port it to MQX 4.0, but I can't get the spi driver install to work.

 

Here is working code for MQX 3.8:

//Prepare the initialization struct  

   init->CHANNEL = 2;

   init->CS = cspin;

   init->TRANSFER_MODE = transfermode;

   init->BAUD_RATE = baudrate;

   init->CLOCK_SPEED = sysclock;

   init->CLOCK_POL_PHASE = clockmode;

   init->RX_BUFFER_SIZE = 1;

   init->TX_BUFFER_SIZE = 1;

  

 

 

   //Set the pins to their secondary function

  /* clock gate */

  SIM_SCGC6 |= SIM_SCGC6_DSPI0_MASK|SIM_SCGC6_DSPI1_MASK;

  SIM_SCGC3 |= SIM_SCGC3_DSPI2_MASK;

  SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTB_MASK;

  /* pin mux */

  PORTD_PCR11 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR11 |= PORT_PCR_MUX(2); //SPI2_PCS0

  PORTD_PCR12 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR12 |= PORT_PCR_MUX(2); //SPI2_SCK

  PORTD_PCR13 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR13 |= PORT_PCR_MUX(2); //SPI2_SOUT

  PORTD_PCR14 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR14 |= PORT_PCR_MUX(2); //SPI2_SIN  

  

   //The fopen call doesn't install the driver with our initialization

   _dspi_polled_install("spi0:", init); //Modified-for-Kinetis

 

SPI_INIT_STRUCT init_struct;

  SPI_PARAM_STRUCT params;

  DSPI_INIT_STRUCT dinit;

  dinit.CHANNEL = 2;

  dinit.CLOCK_SOURCE = sysclock;

 

 

  params.BAUDRATE = baudrate;

  params.CS = cspin;

  params.MODE = clockmode;

  params.ATTR = DSPI_ATTR_USE_ISR;

  params.DUMMY_PATTERN = 0xFFFFFFFF;

 

 

 

 

  init_struct.DEVIF = &_spi_dspi_devif;

  init_struct.DEVIF_INIT = &dinit;

  init_struct.PARAMS = params;

 

 

   //Set the pins to their secondary function

  /* clock gate */

  SIM_SCGC6 |= SIM_SCGC6_DSPI0_MASK|SIM_SCGC6_DSPI1_MASK;

  SIM_SCGC3 |= SIM_SCGC3_DSPI2_MASK;

  SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTB_MASK;

  /* pin mux */

  PORTD_PCR11 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR11 |= PORT_PCR_MUX(2); //SPI2_PCS0

  PORTD_PCR12 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR12 |= PORT_PCR_MUX(2); //SPI2_SCK

  PORTD_PCR13 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR13 |= PORT_PCR_MUX(2); //SPI2_SOUT

  PORTD_PCR14 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR14 |= PORT_PCR_MUX(2); //SPI2_SIN  

  

   //The fopen call doesn't install the driver with our initialization

  _io_spi_install("spi0:", &init_struct);

 

and I replaced it with this:

 

 

SPI_INIT_STRUCT init_struct;

  SPI_PARAM_STRUCT params;

  DSPI_INIT_STRUCT dinit;

  dinit.CHANNEL = 2;

  dinit.CLOCK_SOURCE = sysclock;

  params.BAUDRATE = baudrate;

  params.CS = cspin;

  params.MODE = clockmode;

  params.ATTR = DSPI_ATTR_USE_ISR;

  params.DUMMY_PATTERN = 0xFFFFFFFF;

  init_struct.DEVIF = &_spi_dspi_devif;

  init_struct.DEVIF_INIT = &dinit;

  init_struct.PARAMS = params;

   //Set the pins to their secondary function

  /* clock gate */

  SIM_SCGC6 |= SIM_SCGC6_DSPI0_MASK|SIM_SCGC6_DSPI1_MASK;

  SIM_SCGC3 |= SIM_SCGC3_DSPI2_MASK;

  SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTB_MASK;

  /* pin mux */

  PORTD_PCR11 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR11 |= PORT_PCR_MUX(2); //SPI2_PCS0

  PORTD_PCR12 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR12 |= PORT_PCR_MUX(2); //SPI2_SCK

  PORTD_PCR13 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR13 |= PORT_PCR_MUX(2); //SPI2_SOUT

  PORTD_PCR14 &= ~PORT_PCR_MUX_MASK;

  PORTD_PCR14 |= PORT_PCR_MUX(2); //SPI2_SIN  

   //The fopen call doesn't install the driver with our initialization

  _io_spi_install("spi0:", &init_struct);

But it isn't working. It gives no error at all, it seems to communicate with the ADC, but it doesn't write nor read the values.

 

Any hints would be greatly appreciated.

 

Thanks,

Sebastian

Outcomes