Stuck with SPI0

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Stuck with SPI0

跳至解决方案
1,535 次查看
Nouchi
Senior Contributor II

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

0 项奖励
1 解答
1,084 次查看
timesyssupport
Senior Contributor II

Hi Emmanuel,

I have several questions for you: Can you share your entire program source so we can attempt to reproduce? Does this issue occur on the Vybrid Tower kit, or your custom hardware? Are you booting just MQX, or MQX and Linux? Have you defined the BSPCFG_DSPI0_USE_DMA macro? If you have, can you undef this, and let me know if the issue still occurs, in order to narrow this down to a DMA problem?

Thanks,

Timesys Support

在原帖中查看解决方案

0 项奖励
3 回复数
1,085 次查看
timesyssupport
Senior Contributor II

Hi Emmanuel,

I have several questions for you: Can you share your entire program source so we can attempt to reproduce? Does this issue occur on the Vybrid Tower kit, or your custom hardware? Are you booting just MQX, or MQX and Linux? Have you defined the BSPCFG_DSPI0_USE_DMA macro? If you have, can you undef this, and let me know if the issue still occurs, in order to narrow this down to a DMA problem?

Thanks,

Timesys Support

0 项奖励
1,084 次查看
Nouchi
Senior Contributor II

Hello,

setting BSPCFG_DSPI0_USE_DMA to 0, is the right answer, and works fine.

Now, I need to enable SPI1, but it's another story.

Thanks,

Emmanuel

0 项奖励
1,084 次查看
karina_valencia
NXP Apps Support
NXP Apps Support

timesyssupport can you attend this case?

0 项奖励