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, ¶m);
param = SPI_CLK_POL_PHA_MODE2; // Inactive SPICLK high, sample on leading edge
res = ioctl (spi0fd, IO_IOCTL_SPI_SET_MODE, ¶m);
param = SPI_DEVICE_BIG_ENDIAN; // MSB first
res = ioctl (spi0fd, IO_IOCTL_SPI_SET_ENDIAN, ¶m);
param = 8; // 16 bits data + 8 bits status
res = ioctl (spi0fd, IO_IOCTL_SPI_SET_FRAMESIZE, ¶m);
param = SPI_DEVICE_MASTER_MODE;
res = ioctl (spi0fd, IO_IOCTL_SPI_SET_TRANSFER_MODE, ¶m);
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
Solved! Go to Solution.
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
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
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
timesyssupport can you attend this case?