Driver API for SPI (plib_spi0.h) More...
Macros | |
| #define | SPI_BAUD_MAX (0xFFU) |
| Maximum value for the SPI baud rate register (SCBR field). | |
Typedefs | |
| typedef void(* | SPI_CALLBACK) (uint32_t intr) |
| Callback function type for SPI interrupts. | |
Enumerations | |
| enum | SPI_HWREG_STATUS { SPI_HWREG_OK = 0 , SPI_HWREG_ERROR , SPI_HWREG_INVALID_PARAM , SPI_HWREG_TIMEOUT , SPI_HWREG_BUSY , SPI_HWREG_UNSUPPORTED } |
| Status codes for SPI hardware register operations. More... | |
| enum | SPI_OPERATING_MODE { SPI_CLIENT_MODE = 0U , SPI_HOST_MODE = 1U } |
| SPI operating modes. More... | |
| enum | SPI_PERIPHERAL_SELECT_MODE { SPI_FIXED_PERIPHERAL_SELECT = 0U , SPI_VARIABLE_PERIPHERAL_SELECT = 1U } |
| Peripheral select mode: fixed or variable per transfer. More... | |
| enum | SPI_PCS_DECODE { SPI_CHIP_SELECT_DIRECT = 0U , SPI_CHIP_SELECT_DECODE = 1U } |
| Chip select decoding mode: direct NPCS pins or external decoder. More... | |
| enum | SPI_MODE_FAULT { SPI_MODE_FAULT_ENABLE = 0U , SPI_MODE_FAULT_DISABLE = 1U } |
| Mode fault detection: enable to detect host conflicts. More... | |
| enum | SPI_TRANSFERFLOW_MODE { SPI_TRANSFER_FLOW_NORMAL = 0U , SPI_TRANSFER_FLOW_WAIT_FOR_READ = 1U } |
| Transfer flow control: continuous or wait-for-read. More... | |
| enum | SPI_LOOPBACK { SPI_LOOPBACK_DISABLE = 0U , SPI_LOOPBACK_ENABLE = 1U } |
| Internal loopback mode: disabled for normal operation, enabled for self-test. More... | |
| enum | SPI_TRANSFER_SIZE { SPI_TRANSFER_SIZE_8BIT = 0U , SPI_TRANSFER_SIZE_9BIT = 1U , SPI_TRANSFER_SIZE_10BIT = 2U , SPI_TRANSFER_SIZE_11BIT = 3U , SPI_TRANSFER_SIZE_12BIT = 4U , SPI_TRANSFER_SIZE_13BIT = 5U , SPI_TRANSFER_SIZE_14BIT = 6U , SPI_TRANSFER_SIZE_15BIT = 7U , SPI_TRANSFER_SIZE_16BIT = 8U } |
| SPI character/transfer size options. More... | |
| enum | SPI_INTERRUPT_SOURCE { SPI_INTERRUPT_NONE = 0U , SPI_INTERRUPT_RDRF = (1U << SPI_IER_RDRF_Pos) , SPI_INTERRUPT_TDRE = (1U << SPI_IER_TDRE_Pos) , SPI_INTERRUPT_MODF = (1U << SPI_IER_MODF_Pos) , SPI_INTERRUPT_OVRES = (1U << SPI_IER_OVRES_Pos) , SPI_INTERRUPT_NSSR = (1U << SPI_IER_NSSR_Pos) , SPI_INTERRUPT_TXEMPTY = (1U << SPI_IER_TXEMPTY_Pos) , SPI_INTERRUPT_UNDES = (1U << SPI_IER_UNDES_Pos) , SPI_INTERRUPT_ALL } |
| SPI interrupt sources. More... | |
| enum | SPI_INTERRUPT_FLAG { SPI_FLAG_RDRF = (1U << SPI_SR_RDRF_Pos) , SPI_FLAG_TDRE = (1U << SPI_SR_TDRE_Pos) , SPI_FLAG_MODF = (1U << SPI_SR_MODF_Pos) , SPI_FLAG_OVRES = (1U << SPI_SR_OVRES_Pos) , SPI_FLAG_NSSR = (1U << SPI_SR_NSSR_Pos) , SPI_FLAG_TXEMPTY = (1U << SPI_SR_TXEMPTY_Pos) , SPI_FLAG_UNDES = (1U << SPI_SR_UNDES_Pos) , SPI_FLAG_ALL } |
| SPI interrupt flags. More... | |
Functions | |
| void | SPI0_Enable (void) |
| Enable the SPI module. | |
| void | SPI0_Disable (void) |
| Disable the SPI module. | |
| void | SPI0_Send (uint16_t data) |
| Send a single data word via SPI. | |
| uint16_t | SPI0_Receive (void) |
| Receive a single data word via SPI. | |
| bool | SPI0_RxIsReady (void) |
| Check if SPI receiver is ready. | |
| bool | SPI0_TxIsReady (void) |
| Check if SPI transmitter is ready. | |
| bool | SPI0_TransferIsComplete (void) |
| Check if SPI transmit shift register is empty. | |
| void | SPI0_SetCallbackHandler (SPI_CALLBACK callback) |
| Register an interrupt callback handler. | |
| void | SPI0_EnableInterrupt (SPI_INTERRUPT_SOURCE src) |
| Enable a specific SPI interrupt source. | |
| void | SPI0_DisableInterrupt (SPI_INTERRUPT_SOURCE src) |
| Disable a specific SPI interrupt source. | |
| bool | SPI0_InterruptFlagIsSet (SPI_INTERRUPT_FLAG flag) |
| Check if a specific interrupt flag is set. | |
| void | SPI0_ResetSoftware (void) |
| Perform a software reset of the SPI module. | |
| SPI_HWREG_STATUS | SPI0_SetBusSpeed (uint32_t bus_speed, uint32_t clk_frequency) |
| Set the SPI bus speed. | |
| uint32_t | SPI0_GetBusSpeed (uint32_t clk_frequency) |
| Get the current SPI bus speed. | |
| void | SPI0_SetClockPolarity (bool cpol_high) |
| Set the SPI clock polarity. | |
| void | SPI0_SetClockPhase (bool cpha_trailing) |
| Set the SPI clock phase. | |
| void | SPI0_SetOperatingMode (SPI_OPERATING_MODE mode) |
| Set the SPI operating mode (Host or Client). | |
| void | SPI0_SetBitsPerTransfer (SPI_TRANSFER_SIZE size) |
| Set the SPI character/transfer size. | |
| void | SPI0_SetPeripheralSelectMode (SPI_PERIPHERAL_SELECT_MODE mode) |
| Set the peripheral select mode. | |
| void | SPI0_ChipSelectSetup (uint8_t chipSelect) |
| Setup the chip select line. | |
| void | SPI0_SetPCSDecode (SPI_PCS_DECODE decode) |
| Set the PCS decode mode. | |
| void | SPI0_SetModeFault (SPI_MODE_FAULT fault) |
| Set the mode fault behavior. | |
| void | SPI0_SetTransferFlowMode (SPI_TRANSFERFLOW_MODE mode) |
| Set the transfer flow control mode. | |
| void | SPI0_SetLoopback (SPI_LOOPBACK loopback) |
| Set the SPI loopback mode. | |
| void | SPI0_SetDelayBetweenCS (uint8_t delay) |
| Set the delay between chip select transitions. | |
| void | SPI0_SetDelayBetweenTransfers (uint8_t delay) |
| Set the delay between consecutive SPI transfers. | |
| void | SPI0_SetDelayBeforeSPCK (uint8_t delay) |
| Set the delay before SPI clock signal. | |
| void | SPI0_SetCSActiveAfterTransfer (bool cs_active) |
| Set chip select to remain active after transfer. | |
| void | SPI0_SetCSNotActiveAfterTransfer (bool cs_not_active) |
| Set chip select to not be active after transfer. | |
| void | SPI0_EndTransfer (void) |
| Signal the end of the current SPI transfer in Host mode. | |
| void | SPI0_EnableWriteProtection (void) |
| Enable write protection for SPI registers. | |
| void | SPI0_DisableWriteProtection (void) |
| Disable write protection for SPI registers. | |
| bool | SPI0_WriteProtectionIsEnabled (void) |
| Check if write protection is enabled. | |
| bool | SPI0_WriteProtectedIsViolated (void) |
| Check if a write protection violation has occurred. | |
| uint8_t | SPI0_GetViolationSourceRegOffset (void) |
| Get the register offset of the write protection violation source. | |
Driver API for SPI (plib_spi0.h)
| #define SPI_BAUD_MAX (0xFFU) |
Maximum value for the SPI baud rate register (SCBR field).
| SPI_CALLBACK |
Callback function type for SPI interrupts.
| intr | The interrupt source that triggered the callback. |
| enum SPI_HWREG_STATUS |
| enum SPI_INTERRUPT_FLAG |
| enum SPI_INTERRUPT_SOURCE |
| enum SPI_LOOPBACK |
| enum SPI_MODE_FAULT |
| enum SPI_OPERATING_MODE |
| enum SPI_PCS_DECODE |
| enum SPI_TRANSFER_SIZE |
| void SPI0_ChipSelectSetup | ( | uint8_t | chipSelect | ) |
Setup the chip select line.
Configures the PCS (Peripheral Chip Select) field in SPI_MR to select which chip select line(s) will be used for Fixed Peripheral Select mode. In Variable mode, the PCS is encoded per-transfer in SPI_TDR.
The SPI0 peripheral supports 4 chip select outputs (NPCS0-3), or up to 15 peripherals when using external chip select decoding.
| chipSelect | The chip select value to configure:
|
| void SPI0_Disable | ( | void | ) |
Disable the SPI module.
Disables the SPI0 peripheral by setting the SPIDIS bit in SPI_CR. The function ensures that ongoing transfers are completed before shutdown. After disabling, the peripheral clock can be switched off. Register configuration is preserved.
| void SPI0_DisableInterrupt | ( | SPI_INTERRUPT_SOURCE | src | ) |
Disable a specific SPI interrupt source.
Disables the specified interrupt(s) by setting the corresponding bits in SPI_IDR (Interrupt Disable Register). When disabled, SPI interrupts of those types will not trigger the ISR or invoke the callback, but the interrupt flag(s) may still be set in SPI_SR and can be polled.
| src | One or more interrupt source(s) (OR'd together) to disable. Example: DisableInterrupt(SPI_INTERRUPT_RDRF | SPI_INTERRUPT_TDRE) |
| void SPI0_DisableWriteProtection | ( | void | ) |
Disable write protection for SPI registers.
Disables write protection by clearing the WPEN (Write Protection Enable) bit in SPI_WPMR. When disabled, protected registers can be freely modified.
Use this function when:
| void SPI0_Enable | ( | void | ) |
Enable the SPI module.
Enables the SPI0 peripheral by setting the SPIEN bit in SPI_CR. After enabling, the TDRE and TXEMPTY flags are automatically set, allowing data transfers to begin. The peripheral clock must be enabled via PMC before calling this function.
| void SPI0_EnableInterrupt | ( | SPI_INTERRUPT_SOURCE | src | ) |
Enable a specific SPI interrupt source.
Enables the specified interrupt(s) by setting the corresponding bits in SPI_IER (Interrupt Enable Register). When enabled, SPI interrupts will trigger the ISR, which invokes the registered callback (if set via SetCallbackHandler).
Available interrupt sources (SPI_INTERRUPT_SOURCE):
| src | One or more interrupt source(s) (OR'd together) to enable. Example: EnableInterrupt(SPI_INTERRUPT_RDRF | SPI_INTERRUPT_TDRE) |
| void SPI0_EnableWriteProtection | ( | void | ) |
Enable write protection for SPI registers.
Enables write protection by setting the WPEN (Write Protection Enable) bit in SPI_WPMR (Write Protection Mode Register). When enabled, protected registers cannot be modified; attempts to write will trigger a write protection violation.
Protected registers include:
Write protection helps prevent accidental or malicious modification of critical SPI configuration in safety-critical or automotive applications.
| void SPI0_EndTransfer | ( | void | ) |
Signal the end of the current SPI transfer in Host mode.
Sets the LASTXFER (Last Transfer) bit in SPI_CR to signal that the current transfer is the final one in a sequence. This is used in Host mode to indicate when to deassert the chip select (NPCS) signal after the current transmission completes.
Use case: When communicating with a Client device that requires NPCS to be deasserted between transactions, this function signals the end of the current transaction so that the next NPCS assertion starts a new transaction.
In Host mode with fixed chip select:
| uint32_t SPI0_GetBusSpeed | ( | uint32_t | clk_frequency | ) |
Get the current SPI bus speed.
Reads the SCBR (Serial Clock Bit Rate) value from SPI_CSR0 and calculates the actual SPI serial clock (SPCK) frequency. The calculation is: SPCK = peripheral_clock / SCBR
| clk_frequency | The peripheral clock frequency in Hz. |
| uint8_t SPI0_GetViolationSourceRegOffset | ( | void | ) |
Get the register offset of the write protection violation source.
Reads the WPVSRC (Write Protection Violation Source) field in SPI_WPSR to determine which protected register was the target of the failed write attempt. This helps identify which configuration register code was trying to modify when protection was enabled.
Typical protected register offsets:
| bool SPI0_InterruptFlagIsSet | ( | SPI_INTERRUPT_FLAG | flag | ) |
Check if a specific interrupt flag is set.
Tests the specified interrupt flag in SPI_SR (Status Register) to determine if the corresponding event has occurred. This is useful for polling-based operation or to manually check status within an ISR.
Available interrupt flags (SPI_INTERRUPT_FLAG):
| flag | The interrupt flag to check (SPI_INTERRUPT_FLAG value). |
| uint16_t SPI0_Receive | ( | void | ) |
Receive a single data word via SPI.
Reads data from the SPI_RDR (Receive Data Register) that was shifted in from the SPI bus (MISO line for Host mode, MOSI line for Client mode). The data was collected during the previous transfer. The actual number of bits received (8-16) is determined by the bits per transfer configuration (SPI_CSRx.BITS).
Reading SPI_RDR clears the RDRF (Receive Data Register Full) flag. If new data arrives before the previous data is read, the OVRES (Overrun Error) flag is set in SPI_SR.
| void SPI0_ResetSoftware | ( | void | ) |
Perform a software reset of the SPI module.
Resets the SPI module to its initial state by setting the SWRST bit in SPI_CR. After reset, all registers return to their default values:
After calling this function, the SPI peripheral must be reconfigured before use.
| bool SPI0_RxIsReady | ( | void | ) |
Check if SPI receiver is ready.
Tests the RDRF (Receive Data Register Full) flag in SPI_SR to determine if the receiver has data available to read. RDRF is set when data is transferred from the internal shift register to SPI_RDR after a complete transfer.
| void SPI0_Send | ( | uint16_t | data | ) |
Send a single data word via SPI.
Writes data to the SPI_TDR (Transmit Data Register) to initiate a data transfer. The data is immediately transferred to the internal shift register, and transmission begins on the SPI bus (MOSI line for Host mode, MISO line for Client mode). The actual number of bits transmitted (8-16) is determined by the bits per transfer configuration (SPI_CSRx.BITS).
In Host mode, the SPCK is driven by the baud rate generator. In Client mode, transmission is synchronized by the external SPCK from the Host.
| data | The data word to transmit (8 to 16 bits; upper bits are ignored for smaller transfers). |
| void SPI0_SetBitsPerTransfer | ( | SPI_TRANSFER_SIZE | size | ) |
Set the SPI character/transfer size.
Configures the BITS field in SPI_CSR0 to set the number of bits transferred per SPI transaction. Supported sizes are 8 to 16 bits, corresponding to the SPI_TRANSFER_SIZE enum values (0-8).
The actual data width in SPI_TDR and SPI_RDR is still 16 bits, but only the configured number of bits are actually transmitted/received on the SPI bus. Extra bits are padded with zeros or ignored.
| size | Number of bits per transfer (SPI_TRANSFER_SIZE enum):
|
| SPI_HWREG_STATUS SPI0_SetBusSpeed | ( | uint32_t | bus_speed, |
| uint32_t | clk_frequency ) |
Set the SPI bus speed.
Configures the SPI clock bit rate (baud rate) by calculating and setting the SCBR (Serial Clock Bit Rate) field in SPI_CSR0. The SCBR divides the peripheral clock to generate the SPI serial clock (SPCK). The baud rate is calculated as: SPCK = peripheral_clock / SCBR
The SCBR value is computed as: SCBR = peripheral_clock / bus_speed and is clamped to the range [1, 255] (SPI_BAUD_MAX).
| bus_speed | The desired SPI bus speed in Hz (SPCK frequency). |
| clk_frequency | The peripheral clock frequency in Hz. |
| void SPI0_SetCallbackHandler | ( | SPI_CALLBACK | callback | ) |
Register an interrupt callback handler.
Registers a user-defined callback function to be invoked from the SPI interrupt service routine (ISR) when any enabled SPI interrupt occurs. The callback receives the interrupt source (SPI_INTERRUPT_SOURCE) as a parameter.
Multiple interrupts can be enabled simultaneously (RDRF, TDRE, MODF, OVRES, etc.), and the same callback will be called for all enabled sources. The application must check the interrupt source parameter to determine which event occurred.
| callback | Function pointer to the callback handler: typedef void (*SPI_CALLBACK)(uint8_t intr); where intr contains the interrupt source flags (SPI_INTERRUPT_SOURCE). |
| void SPI0_SetClockPhase | ( | bool | cpha_trailing | ) |
Set the SPI clock phase.
Configures the NCPHA (inverted Clock Phase) bit in SPI_CSR0 to set which clock edge is used for data capture and shifting:
CPHA = 0 (Leading edge capture, NCPHA=1):
CPHA = 1 (Trailing edge capture, NCPHA=0):
The combination of CPOL and CPHA selects the SPI mode (0-3):
| cpha_trailing | true for CPHA=1 (trailing edge capture, NCPHA cleared); false for CPHA=0 (leading edge capture, NCPHA set). |
| void SPI0_SetClockPolarity | ( | bool | cpol_high | ) |
Set the SPI clock polarity.
Configures the CPOL (Clock Polarity) bit in SPI_CSR0 to set the idle state of the SPCK signal:
CPOL = 0 (Clock idles LOW):
CPOL = 1 (Clock idles HIGH):
| cpol_high | true for CPOL=1 (clock idles HIGH); false for CPOL=0 (clock idles LOW). |
| void SPI0_SetCSActiveAfterTransfer | ( | bool | cs_active | ) |
Set chip select to remain active after transfer.
Configures the CSAAT (Chip Select Active After Transfer) bit in SPI_CSR0 to control whether the chip select (NPCS) remains active (low) after the current transfer completes. This is useful for multi-byte transfers where chip select should stay asserted between consecutive bytes.
CSAAT = 0 (Default - Deasserted after transfer):
CSAAT = 1 (Active after transfer):
| cs_active | true to keep NPCS active (low) after transfer; false to deassert NPCS (go high) after transfer. |
| void SPI0_SetCSNotActiveAfterTransfer | ( | bool | cs_not_active | ) |
Set chip select to not be active after transfer.
Configures the CSNAAT (Chip Select Not Active After Transfer) bit in SPI_CSR0 to control whether the chip select (NPCS) should be deasserted (driven high) after the current transfer completes. This provides an alternative way to manage chip select behavior compared to CSAAT.
CSNAAT = 0 (CS active after transfer):
CSNAAT = 1 (CS not active after transfer):
| cs_not_active | true to set CSNAAT bit (NPCS deasserted after transfer); false to clear CSNAAT bit (NPCS remains active after transfer). |
| void SPI0_SetDelayBeforeSPCK | ( | uint8_t | delay | ) |
Set the delay before SPI clock signal.
Configures the DLYBS (Delay Before SPCK) field in SPI_CSR0 to set the minimum delay between chip select assertion (NPCS low) and the first rising edge of the SPI clock (SPCK). This allows Client devices time to prepare after being selected.
The delay is specified in peripheral clock cycles: delay = DLYBS * peripheral_clock_period
Typical use cases:
| delay | The delay in peripheral clock cycles (0-255):
|
| void SPI0_SetDelayBetweenCS | ( | uint8_t | delay | ) |
Set the delay between chip select transitions.
Configures the DLYBCS (Delay Between Chip Selects) field in SPI_MR to set the minimum delay between the deassertion of one chip select (NPCS) and the assertion of another NPCS. This delay allows Client devices time to deactivate before the next device is selected.
The delay is specified in peripheral clock cycles: delay = (DLYBCS + 1) * peripheral_clock_period
Typical use cases:
| delay | The delay in peripheral clock cycles (0-255):
|
| void SPI0_SetDelayBetweenTransfers | ( | uint8_t | delay | ) |
Set the delay between consecutive SPI transfers.
Configures the DLYBCT (Delay Between Consecutive Transfers) field in SPI_CSR0 to set the minimum delay between the end of one transfer and the start of the next. This delay applies only when the same chip select is used for consecutive transfers.
The delay is specified in peripheral clock cycles: delay = (DLYBCT + 1) * peripheral_clock_period
Typical use cases:
| delay | The delay in peripheral clock cycles (0-255):
|
| void SPI0_SetLoopback | ( | SPI_LOOPBACK | loopback | ) |
Set the SPI loopback mode.
Configures the LLB (Local Loopback) bit in SPI_MR to enable or disable internal loopback mode. Loopback is useful for self-testing and debugging without requiring external hardware connections.
Loopback Disabled (SPI_LOOPBACK_DISABLE):
Loopback Enabled (SPI_LOOPBACK_ENABLE):
| loopback | SPI_LOOPBACK_DISABLE for normal operation; SPI_LOOPBACK_ENABLE for internal loopback testing. |
| void SPI0_SetModeFault | ( | SPI_MODE_FAULT | fault | ) |
Set the mode fault behavior.
Configures the MODFDIS (Mode Fault Detection Disable) bit in SPI_MR to enable or disable mode fault detection. Mode fault detection helps identify configuration conflicts in Host mode.
Mode Fault Enabled (SPI_MODE_FAULT_ENABLE):
Mode Fault Disabled (SPI_MODE_FAULT_DISABLE):
| fault | SPI_MODE_FAULT_ENABLE to detect mode faults; SPI_MODE_FAULT_DISABLE to bypass detection. |
| void SPI0_SetOperatingMode | ( | SPI_OPERATING_MODE | mode | ) |
Set the SPI operating mode (Host or Client).
Configures the MSTR (Master) bit in SPI_MR to set the SPI operating mode:
Host Mode (SPI_HOST_MODE):
Client Mode (SPI_CLIENT_MODE):
| mode | SPI_HOST_MODE for Host (master) operation; SPI_CLIENT_MODE for Client (slave) operation. |
| void SPI0_SetPCSDecode | ( | SPI_PCS_DECODE | decode | ) |
Set the PCS decode mode.
Configures the PCSDEC (Peripheral Chip Select Decode) bit in SPI_MR to enable or disable external chip select decoding via an external decoder/demultiplexer.
Direct Mode (SPI_CHIP_SELECT_DIRECT):
Decoded Mode (SPI_CHIP_SELECT_DECODE):
| decode | SPI_CHIP_SELECT_DIRECT to use NPCS pins directly; SPI_CHIP_SELECT_DECODE to use external decoder. |
| void SPI0_SetPeripheralSelectMode | ( | SPI_PERIPHERAL_SELECT_MODE | mode | ) |
Set the peripheral select mode.
Configures the PS (Peripheral Select) bit in SPI_MR to select between Fixed and Variable peripheral selection modes. This mode applies to Host mode operation.
Fixed Peripheral Select Mode (SPI_FIXED_PERIPHERAL_SELECT):
Variable Peripheral Select Mode (SPI_VARIABLE_PERIPHERAL_SELECT):
| mode | SPI_FIXED_PERIPHERAL_SELECT for single peripheral; SPI_VARIABLE_PERIPHERAL_SELECT for multiple peripherals. |
| void SPI0_SetTransferFlowMode | ( | SPI_TRANSFERFLOW_MODE | mode | ) |
Set the transfer flow control mode.
Configures the WDRBT (Wait Data Read Before Transfer) bit in SPI_MR to control whether new data can be written to SPI_TDR before the previous receive data is read.
Normal Flow (SPI_TRANSFER_FLOW_NORMAL):
Wait-for-Read Flow (SPI_TRANSFER_FLOW_WAIT_FOR_READ):
| mode | SPI_TRANSFER_FLOW_NORMAL for continuous flow (no read requirement); SPI_TRANSFER_FLOW_WAIT_FOR_READ to require read before new transmit. |
| bool SPI0_TransferIsComplete | ( | void | ) |
Check if SPI transmit shift register is empty.
Tests the TXEMPTY (Transmit Shift Register Empty) flag in SPI_SR to determine if all data has been transmitted and the shift register is idle. TXEMPTY is set when both the Transmit Data Register (TDR) and the shift register are empty, meaning no data is being transmitted on the SPI bus.
| bool SPI0_TxIsReady | ( | void | ) |
Check if SPI transmitter is ready.
Tests the TDRE (Transmit Data Register Empty) flag in SPI_SR to determine if the transmitter is ready to accept new data. TDRE is set when data from SPI_TDR has been loaded into the internal shift register and transmission has started. TDRE is cleared when new data is written to SPI_TDR.
| bool SPI0_WriteProtectedIsViolated | ( | void | ) |
Check if a write protection violation has occurred.
Tests the WPVS (Write Protection Violation Status) bit in SPI_WPSR (Write Protection Status Register) to determine if an attempt to write to a protected register was detected. This flag is set when write protection is enabled (WPEN=1) and code attempts to modify a protected register.
| bool SPI0_WriteProtectionIsEnabled | ( | void | ) |
Check if write protection is enabled.
Tests the WPEN (Write Protection Enable) bit in SPI_WPMR to determine if write protection is currently active. When enabled, protected registers cannot be modified.