API Reference
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_twi.c File Reference

Two-Wire Interface Controller (TWI) HW driver source file. More...

#include <neorv32.h>

Functions

int neorv32_twi_available (void)
void neorv32_twi_setup (int prsc, int cdiv)
uint32_t neorv32_twi_get_fifo_depth (void)
uint32_t neorv32_twi_get_clock (void)
int neorv32_twi_sense_scl (void)
int neorv32_twi_sense_sda (void)
int neorv32_twi_claimed (void)
int neorv32_twi_check_nack (void)
void neorv32_twi_irq_clr (void)
int neorv32_twi_busy (void)
int neorv32_twi_rx_avail (void)
int neorv32_twi_tx_full (void)
uint8_t neorv32_twi_rx_get (void)
void neorv32_twi_start (void)
void neorv32_twi_stop (void)
void neorv32_twi_tx (uint8_t data)
void neorv32_twi_rx_ack (void)
void neorv32_twi_rx_nack (void)

Detailed Description

Two-Wire Interface Controller (TWI) HW driver source file.

Function Documentation

◆ neorv32_twi_available()

int neorv32_twi_available ( void )

Check if TWI unit was synthesized.

Returns
0 if TWI was not synthesized, non-zero if TWI is available.

◆ neorv32_twi_busy()

int neorv32_twi_busy ( void )

Check if TWI controller is busy (TWI bus engine busy or TX FIFO not empty).

Returns
Zero if idle, non-zero if busy.

◆ neorv32_twi_check_nack()

int neorv32_twi_check_nack ( void )

Check if a TX transfer returned a NACK and clear NACK flag.

Returns
Zero if no NACK, non-zero if any TX transmission returned a NACK.

◆ neorv32_twi_claimed()

int neorv32_twi_claimed ( void )

Check if bus is (still) claimed by TWI controller.

Returns
Non-zero if bus is claimed, zero if bus is released.

◆ neorv32_twi_get_clock()

uint32_t neorv32_twi_get_clock ( void )

Get programmed TWI bus clock speed.

Returns
Clock speed in Hz.

◆ neorv32_twi_get_fifo_depth()

uint32_t neorv32_twi_get_fifo_depth ( void )

Get TWI FIFO depth.

Returns
FIFO depth (number of entries).

◆ neorv32_twi_irq_clr()

void neorv32_twi_irq_clr ( void )

Clear/acknowledge interrupt request.

◆ neorv32_twi_rx_ack()

void neorv32_twi_rx_ack ( void )

Issue RX data transmission with ACK (read from bus).

Note
Function blocks until command can be issued.

◆ neorv32_twi_rx_avail()

int neorv32_twi_rx_avail ( void )

Check if RX data is available.

Returns
Zero if no data available, non-zero if at least one byte is available.

◆ neorv32_twi_rx_get()

uint8_t neorv32_twi_rx_get ( void )

Get RX data. Check with neorv32_twi_rx_avail before.

Returns
Data read from RX FIFO.

◆ neorv32_twi_rx_nack()

void neorv32_twi_rx_nack ( void )

Issue RX data transmission with NACK (read from bus).

Note
Function blocks until command can be issued.

◆ neorv32_twi_sense_scl()

int neorv32_twi_sense_scl ( void )

Get current state of SCL bus line.

Returns
Non-zero if SCL is high, zero if SCL is low.

◆ neorv32_twi_sense_sda()

int neorv32_twi_sense_sda ( void )

Get current state of SDA bus line.

Returns
Non-zero if SDA is high, zero if SDA is low.

◆ neorv32_twi_setup()

void neorv32_twi_setup ( int prsc,
int cdiv )

Enable and configure TWI controller. The TWI control register bits are listed in NEORV32_TWI_CTRL_enum.

Parameters
[in]prscClock prescaler select (0..7). See NEORV32_CLOCK_PRSC_enum.
[in]cdivClock divider (0..15).

◆ neorv32_twi_start()

void neorv32_twi_start ( void )

Issue START (or REPEATED-START) condition.

Note
Function blocks until command can be issued.

◆ neorv32_twi_stop()

void neorv32_twi_stop ( void )

Issue STOP condition.

Note
Function blocks until command can be issued.

◆ neorv32_twi_tx()

void neorv32_twi_tx ( uint8_t data)

Issue TX data transmission (send data to bus).

Note
Function blocks until command can be issued.
Parameters
[in]dataData byte to be send.

◆ neorv32_twi_tx_full()

int neorv32_twi_tx_full ( void )

Check if TX FIFO is full.

Returns
Zero if at least one free entry left, non-zero if full.