AnsweredAssumed Answered

Stuck with SPI0

Question asked by Nouchi on May 7, 2014
Latest reply on May 12, 2014 by Nouchi

Hello,

 

I'm trying to use SPI0 on M4 side with MQX 4.0.2.

Here is the simple code :

void My_Task(uint32_t data)

{

MQX_FILE_PTR  spi0fd;

LWTIMER_PERIOD_STRUCT timerPeriodQueue;

LWTIMER_STRUCT timer;

volatile _mqx_int res;

int_32 param, ad7171_data;

volatile uint_8 ad7171_status;

 

      set_state(stateMachine);                         /* set switches */

      SET_PDRST;                                        /* start AD7171 */

      _time_delay(30);                                    /* waiting first conversion */

      _lwevent_create(&lwEvent, LWEVENT_AUTO_CLEAR);

      _lwtimer_create_periodic_queue(&timerPeriodQueue, PERIODE20MS, 0);

      _lwtimer_add_timer_to_queue(&timerPeriodQueue, &timer, 0, periodicEventCallBack, (pointer)MY_EVENT_01);

 

      spi0fd = fopen ("spi0:", NULL);

      if (NULL == spi1fd)

      {

          printf ("Error opening SPI driver!\n");

      }

      param = 1000000;                        // 1Mhz

      res = ioctl (spi0fd, IO_IOCTL_SPI_SET_BAUD, &param);

      param = SPI_CLK_POL_PHA_MODE2;        // Inactive SPICLK high, sample on leading edge

      res = ioctl (spi0fd, IO_IOCTL_SPI_SET_MODE, &param);

      param = SPI_DEVICE_BIG_ENDIAN;        // MSB first

      res = ioctl (spi0fd, IO_IOCTL_SPI_SET_ENDIAN, &param);

      param = 8;                            // 16 bits data + 8 bits status

      res = ioctl (spi0fd, IO_IOCTL_SPI_SET_FRAMESIZE, &param);

      param = SPI_DEVICE_MASTER_MODE;

      res = ioctl (spi0fd, IO_IOCTL_SPI_SET_TRANSFER_MODE, &param);

      while(1)

      {

         res = _lwevent_wait_for(&lwEvent, MY_EVENT_01, TRUE, 0);

         res = fread (&ad7171_data, 3, 1, spi0fd);

 

 

It never returns from fread, I dug deeper, and it seems to be waiting EVENT_IO_FINISHED in _dspi_dma_transfer which never happens.

Nothing output from SPI0_SCK pin, in SPI0_SR, TXRXS is set, and transfer is not complete.

 

 

Does anybody have an idea?

 

Regards,

Emmanuel

Outcomes