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 csen)
 
void neorv32_twi_disable (void)
 
void neorv32_twi_enable (void)
 
void neorv32_twi_mack_enable (void)
 
void neorv32_twi_mack_disable (void)
 
int neorv32_twi_busy (void)
 
int neorv32_twi_start_trans (uint8_t a)
 
int neorv32_twi_trans (uint8_t d)
 
uint8_t neorv32_twi_get_data (void)
 
void neorv32_twi_generate_stop (void)
 
void neorv32_twi_generate_start (void)
 
int neorv32_twi_bus_claimed (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_bus_claimed()

int neorv32_twi_bus_claimed ( void  )

Check if the TWI bus is currently claimed by any controller.

Returns
0: 0 if bus is not claimed, 1 if bus is claimed.

◆ neorv32_twi_busy()

int neorv32_twi_busy ( void  )

Check if TWI is busy.

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_stop()

void neorv32_twi_generate_stop ( void  )

Generate STOP condition.

Note
Blocking function.

◆ neorv32_twi_get_data()

uint8_t neorv32_twi_get_data ( void  )

Get received data from last transmission.

Returns
0: Last received data byte.

◆ neorv32_twi_mack_disable()

void neorv32_twi_mack_disable ( void  )

Deactivate sending ACKs by controller (MACK).

◆ neorv32_twi_mack_enable()

void neorv32_twi_mack_enable ( void  )

Activate sending ACKs by controller (MACK).

◆ neorv32_twi_setup()

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

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]csenAllow clock stretching when 1.

◆ neorv32_twi_start_trans()

int neorv32_twi_start_trans ( uint8_t  a)

Generate START condition and send first byte (address including R/W bit).

Note
Blocking function.
Parameters
[in]aData byte including 7-bit address and R/W-bit (lsb).
Returns
0: ACK received, 1: NACK received.

◆ neorv32_twi_trans()

int neorv32_twi_trans ( uint8_t  d)

Send data byte and also receive data byte (can be read via neorv32_twi_get_data()).

Note
Blocking function.
Parameters
[in]dData byte to be send.
Returns
0: ACK received, 1: NACK received.