Problem with SPI in MK60

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

Problem with SPI in MK60

Jump to solution
532 Views
feraro
Contributor IV

Hello.

I'm trying to communicate through SPI1. I have the code done with MQX 3.7 and works correctly, however with MQX 4.2 not get it to work. I am working in mode polled. Specifically, they do not change the signal BSP_CS0_SPI1, BSP_SPI1_CLK and BSP_SPI1_MOSI. The first writing I do, changes the signal to 0 BSP_CS0_SPI1 a moment, but the other attempts to write, does not change.

In user_config.h I have:

#define BSPCFG_ENABLE_SPI1                        1

#define BSPCFG_DSPI1_USE_DMA                  0      

I have defined

#define TEST_CHANNEL_POLLED "spi1:"

To read/write, I do:

spifd_5422_1 = fopen (TEST_CHANNEL_POLLED, (pointer)(SPI_FLAG_HALF_DUPLEX));

ioctl (spifd_5422_1, IO_IOCTL_SPI_READ_WRITE, &rw_5422_1);

ioctl (spifd_5422_1, IO_IOCTL_SPI_READ_WRITE, &rw_5422_1);

ioctl (spifd_5422_1, IO_IOCTL_SPI_READ_WRITE, &rw_5422_1);

fclose(spifd_5422_1);   

BSP_CS0_SPI1 only change to 0 in the first READ_WRITE

I have to change something to change MQX version?

Thanks.

0 Kudos
1 Solution
393 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Fernando:

The SPI driver in MQX 3.7 is considered obsolete, the legacy SPI is replaced by the new SPI driver.

The most significant change in the new SPI driver framework is the support of the concurrent bus access from multiple task.

The legacy SPI driver does not provide any special support for concurrent access. There may be only a single file handle associated with the SPI device and the application has ensure not using the file handle from multiple tasks at the same time. When there are more slaves connected to the bus, the application also has to handle changing the chip select and possibly also other transfer parameter by issuing IOCTL commands whenever with a different slave is going to take place.

By contrast, the new SPI driver framework fully supports resource sharing. There may be simultaneously open multiple file handles associated with the same SPI device. Each file handle keeps its own set of transfer parameters. In a typical use case, each file handle represents a virtual communication channel connected to a slave device. The application then simply performs read/write/flush operations on the file handles and the SPI driver framework takes care about bus sharing and automatic reconfiguration of transfer parameters any time when this is necessary.

You need to re-write your application code in order to use the new SPI driver.

Regards

Daniel

View solution in original post

1 Reply
394 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Fernando:

The SPI driver in MQX 3.7 is considered obsolete, the legacy SPI is replaced by the new SPI driver.

The most significant change in the new SPI driver framework is the support of the concurrent bus access from multiple task.

The legacy SPI driver does not provide any special support for concurrent access. There may be only a single file handle associated with the SPI device and the application has ensure not using the file handle from multiple tasks at the same time. When there are more slaves connected to the bus, the application also has to handle changing the chip select and possibly also other transfer parameter by issuing IOCTL commands whenever with a different slave is going to take place.

By contrast, the new SPI driver framework fully supports resource sharing. There may be simultaneously open multiple file handles associated with the same SPI device. Each file handle keeps its own set of transfer parameters. In a typical use case, each file handle represents a virtual communication channel connected to a slave device. The application then simply performs read/write/flush operations on the file handles and the SPI driver framework takes care about bus sharing and automatic reconfiguration of transfer parameters any time when this is necessary.

You need to re-write your application code in order to use the new SPI driver.

Regards

Daniel