Set K60 GPIO as SPI chip select with MQX 3.8

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

Set K60 GPIO as SPI chip select with MQX 3.8

Jump to solution
1,001 Views
il_mix
Contributor II

Hi everyone!

 

I would like to connect several SPI devices to my K60. Now I'm testing with the K60N512 tower module.

With a single device attached to the board, I use the SPI2_CS1 signal as chip select, using SPI_PUSHR_PCS(1 << 1) as a parameter for IO_IOCTL_SPI_SET_CS command; in this way I define a default SPI2 chip select signals enable mask for the driver (only the CS set to '1' in the mask will be used by the driver. Am I right?)

Now I would like to use a simple GPIO as chip select (i.e., TWRPI_GPIO1 on PTB8, TWRPI_GPIO2 on PTB9, ...).

Solution 1: don't set any CS for the SPI driver (using 0 as mask for IO_IOCTL_SPI_SET_CS?) and drive the GPIO manually just before and after the SPI operation (GPIO=0 -> read/write SPI -> GPIO=1)

Solution 2: set the GPIO as CS for the SPI driver. I want to use this one ... but how to do it?

 

I've read this post that seems to use the second solution, but I didn't understand wery well various things (how does the CS_MUX works? How to use it?)

Or maybe there's a simpler solution.

 

Any hint will be really appreciated!

Thanks!

0 Kudos
1 Solution
408 Views
Xuejian
Contributor II

Oh, I tested it. It seems we don't need to worry about it if we didn't change BSP. BSP sets and clears CS before and after write/read automatically.

View solution in original post

0 Kudos
2 Replies
408 Views
Xuejian
Contributor II

I have the same question. How to use IO_IOCTL_SPI_SET_CS in ioctl()? Seems no exact example.

0 Kudos
409 Views
Xuejian
Contributor II

Oh, I tested it. It seems we don't need to worry about it if we didn't change BSP. BSP sets and clears CS before and after write/read automatically.

0 Kudos