spi_set_slave should disable SPI #713

Closed
opened 2022-01-19 07:20:40 -06:00 by daveythacher · 6 comments
daveythacher commented 2022-01-19 07:20:40 -06:00 (Migrated from github.com)

According to PrimeCell documentation copied into the RP2040 datasheet SSPCR1::MS should not be modified unless disabled.
https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf

Master or slave mode select. This bit can be modified only
when the PrimeCell SSP is disabled, SSE=0: 0 Device
configured as master, default. 1 Device configured as
slave.

https://developer.arm.com/documentation/ddi0194/h/programmer-s-model/register-descriptions/control-register-1--sspcr1

Master or slave mode select.This bit can be modified only when the PrimeCell SSP is disabled, SSE=0:0Device configured as master, default.1Device configured as slave.

Looking at this, it would appear that we are to call spi_init followed by spi_set_slave. github.com/raspberrypi/pico-sdk@2062372d20/src/rp2_common/hardware_spi/include/hardware/spi.h (L193-L207)

Documentation from https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga1dba14fb5488b5e4a69b30678f774df0

Initialise SPI instances.

Puts the SPI into a known state, and enable it. Must be called before other functions.

SPI is enabled by spi_init. github.com/raspberrypi/pico-sdk@2062372d20/src/rp2_common/hardware_spi/spi.c (L21-L33)

Does the API support SPI? Deinit says I have to call init. I could modify it manually; however, I think this should be corrected. Unless I am missing something.

According to PrimeCell documentation copied into the RP2040 datasheet SSPCR1::MS should not be modified unless disabled. https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf ``` Master or slave mode select. This bit can be modified only when the PrimeCell SSP is disabled, SSE=0: 0 Device configured as master, default. 1 Device configured as slave. ``` https://developer.arm.com/documentation/ddi0194/h/programmer-s-model/register-descriptions/control-register-1--sspcr1 ``` Master or slave mode select.This bit can be modified only when the PrimeCell SSP is disabled, SSE=0:0Device configured as master, default.1Device configured as slave. ``` Looking at this, it would appear that we are to call spi_init followed by spi_set_slave. https://github.com/raspberrypi/pico-sdk/blob/2062372d203b372849d573f252cf7c6dc2800c0a/src/rp2_common/hardware_spi/include/hardware/spi.h#L193-L207 Documentation from https://raspberrypi.github.io/pico-sdk-doxygen/group__hardware__spi.html#ga1dba14fb5488b5e4a69b30678f774df0 ``` Initialise SPI instances. Puts the SPI into a known state, and enable it. Must be called before other functions. ``` SPI is enabled by spi_init. https://github.com/raspberrypi/pico-sdk/blob/2062372d203b372849d573f252cf7c6dc2800c0a/src/rp2_common/hardware_spi/spi.c#L21-L33 Does the API support SPI? Deinit says I have to call init. I could modify it manually; however, I think this should be corrected. Unless I am missing something.
daveythacher commented 2022-01-19 18:31:52 -06:00 (Migrated from github.com)

This would be valid work around?

    spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
    hw_set_bits(&spi_get_hw(spi0)->dmacr, SPI_SSPDMACR_TXDMAE_BITS | SPI_SSPDMACR_RXDMAE_BITS);
    spi_set_slave(spi0, true);
    hw_set_bits(&spi_get_hw(spi0)->cr1, SPI_SSPCR1_SSE_BITS);
This would be valid work around? ```C spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST); hw_set_bits(&spi_get_hw(spi0)->dmacr, SPI_SSPDMACR_TXDMAE_BITS | SPI_SSPDMACR_RXDMAE_BITS); spi_set_slave(spi0, true); hw_set_bits(&spi_get_hw(spi0)->cr1, SPI_SSPCR1_SSE_BITS); ```
daveythacher commented 2022-12-26 02:34:14 -06:00 (Migrated from github.com)

This would be valid work around?

    spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
    hw_set_bits(&spi_get_hw(spi0)->dmacr, SPI_SSPDMACR_TXDMAE_BITS | SPI_SSPDMACR_RXDMAE_BITS);
    spi_set_slave(spi0, true);
    hw_set_bits(&spi_get_hw(spi0)->cr1, SPI_SSPCR1_SSE_BITS);

This worked for me. I had to use SPI Mode 1, because of ARM PrimeCell SPI.

> This would be valid work around? > > ```c > spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST); > hw_set_bits(&spi_get_hw(spi0)->dmacr, SPI_SSPDMACR_TXDMAE_BITS | SPI_SSPDMACR_RXDMAE_BITS); > spi_set_slave(spi0, true); > hw_set_bits(&spi_get_hw(spi0)->cr1, SPI_SSPCR1_SSE_BITS); > ``` This worked for me. I had to use SPI Mode 1, because of ARM PrimeCell SPI.
daveythacher commented 2022-12-26 02:35:44 -06:00 (Migrated from github.com)

To get SPI Mode 1:

spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_1, SPI_MSB_FIRST);
To get SPI Mode 1: ```C spi_set_format(spi0, 8, SPI_CPOL_0, SPI_CPHA_1, SPI_MSB_FIRST); ```
daveythacher commented 2022-12-26 06:52:38 -06:00 (Migrated from github.com)

Pull request: #1158

Pull request: #1158
kilograham commented 2023-05-26 09:00:54 -05:00 (Migrated from github.com)

fixed in 1.5.0

fixed in 1.5.0
daveythacher commented 2024-07-11 15:00:38 -05:00 (Migrated from github.com)

@kilograham Can I get this marked as hardware_spi?

@kilograham Can I get this marked as hardware_spi?
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#713
No description provided.