NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
Functions
neorv32_twi.c File Reference

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

#include "neorv32.h"
#include "neorv32_twi.h"

Functions

int neorv32_twi_available (void)
 
void neorv32_twi_setup (int prsc, int cdiv, int clkstr)
 
int neorv32_twi_get_fifo_depth (void)
 
void neorv32_twi_disable (void)
 
void neorv32_twi_enable (void)
 
int neorv32_twi_busy (void)
 
int neorv32_twi_get (uint8_t *data)
 
int neorv32_twi_trans (uint8_t *data, int mack)
 
void neorv32_twi_generate_stop (void)
 
void neorv32_twi_generate_start (void)
 
void neorv32_twi_send_nonblocking (uint8_t data, int mack)
 
void neorv32_twi_generate_stop_nonblocking (void)
 
void neorv32_twi_generate_start_nonblocking (void)
 

Detailed Description

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

Note
These functions should only be used if the TWI unit was synthesized (IO_TWI_EN = true).

Function Documentation

◆ neorv32_twi_available()

int neorv32_twi_available ( void )

Check if TWI unit was synthesized.

Returns
0 if TWI was not synthesized, 1 if TWI is available.

◆ neorv32_twi_busy()

int neorv32_twi_busy ( void )

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

Returns
0 if idle, 1 if busy

◆ neorv32_twi_disable()

void neorv32_twi_disable ( void )

Disable TWI controller.

◆ neorv32_twi_enable()

void neorv32_twi_enable ( void )

Enable TWI controller.

◆ neorv32_twi_generate_start()

void neorv32_twi_generate_start ( void )

Generate START (or REPEATED-START) condition.

Note
Blocking function.

◆ neorv32_twi_generate_start_nonblocking()

void neorv32_twi_generate_start_nonblocking ( void )

Generate START (or REPEATED-START) condition.

Note
Non-blocking function; does not check the TX FIFO.

◆ neorv32_twi_generate_stop()

void neorv32_twi_generate_stop ( void )

Generate STOP condition.

Note
Blocking function.

◆ neorv32_twi_generate_stop_nonblocking()

void neorv32_twi_generate_stop_nonblocking ( void )

Generate STOP condition.

Note
Non-blocking function; does not check the TX FIFO.

◆ neorv32_twi_get()

int neorv32_twi_get ( uint8_t * data)

Get received data + ACK/NACH from RX FIFO.

Parameters
[in,out]dataPointer for returned data (uint8_t).
Returns
RX FIFO access status (-1 = no data available, 0 = ACK received, 1 = NACK received).

◆ neorv32_twi_get_fifo_depth()

int neorv32_twi_get_fifo_depth ( void )

Get TWI FIFO depth.

Returns
FIFO depth (number of entries), zero if no FIFO implemented

◆ neorv32_twi_send_nonblocking()

void neorv32_twi_send_nonblocking ( uint8_t data,
int mack )

Send data byte (RX can be read via neorv32_twi_get()).

Note
Non-blocking function; does not check the TX FIFO.
Parameters
[in]dataData byte to be send.
[in]mackGenerate ACK by host controller when set.

◆ neorv32_twi_setup()

void neorv32_twi_setup ( int prsc,
int cdiv,
int clkstr )

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).
[in]clkstrEnable (allow) clock stretching.

◆ neorv32_twi_trans()

int neorv32_twi_trans ( uint8_t * data,
int mack )

TWI transfer: send data byte and also receive data byte.

Note
Blocking function.
Parameters
[in,out]dataPointer for TX/RX data (uint8_t).
[in]mackGenerate ACK by host controller when set.
Returns
0: ACK received, 1: NACK received.