NetBurner 3.0
Simple NetBurner I2C Functions

Functions

void Multi_I2CInit (uint8_t slave_Addr=0x08, uint8_t freqdiv=0x3C)
 This is the I2C initialization routine. More...
 
uint8_t Multi_I2CSendBuf (uint8_t addr, puint8_t buf, int num, bool stop=true)
 This function sends a buffer to an address on the I2C bus in master mode without the need of a start and stop bit. More...
 
uint8_t Multi_I2CReadBuf (uint8_t addr, puint8_t buf, int num, bool stop=true)
 This function allows a buffer to be read from an address on the I2C bus in master mode without the need of a start and stop bit. More...
 
bool I2CRXAvail ()
 This function determines if there is data available in the I2C slave receive buffer. More...
 
uint32_t I2CTXAvail ()
 This function determines the free space available in the I2C slave TX buffer. More...
 
uint8_t I2CGetByte ()
 This function will pend on a slave receive I2C semaphore. More...
 
uint8_t I2CFillSlaveTXBuf (puint8_t buf, uint32_t num, bool restart=true)
 This function is used to fill the I2C slave TX buffer. More...
 
uint8_t Multi_I2CRestart (uint8_t addr, bool Read_Not_Write, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
 Send a restart of communication with a slave device after finished communication on the bus. More...
 

Variables

uint8_t(* I2C_SlaveTX_Callback )()
 If this callback is pointed to a function, then it will be called when retrieving the data to be sent to the master. This will bypass the circular buffer functions I2CTXAvail() and I2CFillSlaveTXBuf() used when transmitting data as a slave. More...
 
void(* I2C_SlaveTX_NAK_Callback )()
 If this callback is pointed to a function, then it will be called when the receiving master device sends a NAK. This indicates that the master device will not be reading any more data from the slave transmitter.
 
void(* I2C_SlaveRX_Callback )(uint8_t RX_Data)
 If this callback is pointed to a function then it will be called when storing the data received from the master. This will bypass the circular buffer functions I2CRXAvail() and I2CGetByte() used when receiving data as a slave. More...
 

Detailed Description

The following functions are a used to easily communicate on the I2C bus without the need of configuring timeouts or terminations. These functions will send or receive buffers instead of uint8_t like the advanced functions.

Function Documentation

◆ I2CFillSlaveTXBuf()

uint8_t I2CFillSlaveTXBuf ( puint8_t  buf,
uint32_t  num,
bool  restart = true 
)

This function is used to fill the I2C slave TX buffer.

It will put the first 'num' uint8_t from the buffer 'buf' into the I2C Slave TX buffer and clear the previously-read contents of the buffer. The 'restart' parameter tells the slave transmitter how to terminate

In I2C multi.h there is a I2C_SLAVE_TX_TERM_CHAR defined that will decide the terminating char (if any) to send when the slave TX buffer is empty.

Parameters
bufA pointer to the BYTE buffer that contains data for the slave TX buffer.
numThe number of BYTE to send from buf to TX buffer.
restartIf true then restart next TX from beginning TX buffer (a new slave fill replaces buffer). If false then continue next TX from last slave TX (a new slave fill adds to buffer at last unread byte).
Return values
TRUEIf it copied data
FALSEIf it failed to copy data
See also
Multi_I2CReadBuf()

◆ I2CGetByte()

uint8_t I2CGetByte ( )

This function will pend on a slave receive I2C semaphore.

Returns
The oldest unread byte in the I²C slave RX buffer
See also
I2CRXAvail()
I2CTXAvail()

◆ I2CRXAvail()

bool I2CRXAvail ( )

This function determines if there is data available in the I2C slave receive buffer.

Return values
TRUEIf there is data in the slave RX buffer
FALSEIf slave RX buffer is empty
See also
I2CTXAvail()
I2CGetByte()

◆ I2CTXAvail()

uint32_t I2CTXAvail ( )

This function determines the free space available in the I2C slave TX buffer.

Returns
The number of bytes remaining in the I2C slave TX buffer.
See also
I2CRXAvail()
I2CGetByte()

◆ Multi_I2CInit()

void Multi_I2CInit ( uint8_t  slave_Addr = 0x08,
uint8_t  freqdiv = 0x3C 
)

This is the I2C initialization routine.

Will assign 'slave_Addr' to be the address when module addressed by another master on the I2C bus. Default Address if parameter not included is 0x08.

For MOD54415 Internal bus clock which = (250MHZ (sys clock)/2) / freqdiv to give max baud rate of the master mode I2C bus. Values of freqdiv are found in a the I2FDR table found in the I2C section of the MCF54415 reference manual provided by Freescale (found in <nburn_install>).

Parameters
slave_AddrThe 7-bit slave address assigned to NetBurner and is only used in i2cmulti API. Note: Phillips I2C Standard states that the two group addresses 0000XXX and 1111XXX are reserved for advanced purposes. The addresses 11110XX are also reserved for the 10-bit addressing I2C protocol.
freqdivThis value is used in the Coldfire I2FDR as a prescaler of the system clock to generate a max baud rate of the master mode I2C bus. Valid values for freqdiv are found in the I2C section of your Freescale MCF Manual (in C:). All the processors are set to be approximately 100Kbits by default, which is the max I2C standard speed.
See also
Multi_I2CSendBuf()
Multi_I2CReadBuf()

◆ Multi_I2CReadBuf()

uint8_t Multi_I2CReadBuf ( uint8_t  addr,
puint8_t  buf,
int  num,
bool  stop = true 
)

This function allows a buffer to be read from an address on the I2C bus in master mode without the need of a start and stop bit.

Reads 'num' uint8_tS of buffer 'buf' on the I2C bus to address 'addr'. The transmission is then terminated with a stop signal if user either calls the function with no 'stop' parameter or a stop = true. If user wishes to terminate differently, such as a restart, then 'stop' can be set false and a NetBurner advanced I2Cfunction can be used for termination.

Parameters
addrThe 7-bit address you wish to read the buffer from.
bufA pointer to the BYTE buffer you wish to read to.
numThe number of bytes to read.
stopIf true, Terminate communication with stop. Otherwise, do not terminate transmission. This is useful if the user wishes to send a restart instead of a stop.
Returns
i2cMultiReturnValues
See also
Multi_I2CInit()
Multi_I2CSendBuf()

◆ Multi_I2CRestart()

uint8_t Multi_I2CRestart ( uint8_t  addr,
bool  Read_Not_Write,
uint32_t  ticks_to_wait = I2C_RX_TX_TIMEOUT 
)

Send a restart of communication with a slave device after finished communication on the bus.

This is used instead of a 'stop' and will allow the user to communicate on bus again without giving up control of the bus first. Note: This function should only be used when in master mode and you have control of the bus.

Parameters
addrThe address of the slave device we wish to communicate with on the bus.
Read_Not_WriteSelect True to read, false to write. Note: You can use I2C_START_READ or I2C_START_WRITE as values.
ticks_to_waitThe number of ticks to wait on restart before failing. This includes the time it takes to receive an an ACK from the addressed slave device.
Returns
i2cMultiReturnValues
See also
Multi_I2CStart()
Multi_I2CStop()

◆ Multi_I2CSendBuf()

uint8_t Multi_I2CSendBuf ( uint8_t  addr,
puint8_t  buf,
int  num,
bool  stop = true 
)

This function sends a buffer to an address on the I2C bus in master mode without the need of a start and stop bit.

Sends 'num' uint8_tS of buffer 'buf' on the I2C bus to address 'addr'. The transmission is then terminated with a stop signal if user either calls the function with no 'stop' parameter or a stop = true. If the user wishes to terminate differently, such as a restart, then 'stop' can be set false and a NetBurner advanced I2Cfunction can be used for termination.

Parameters
addrThe 7-bit address you wish to send the buffer to.
bufA pointer to the BYTE buffer you wish to write from.
numThe number of bytes to write.
stopIf true, Terminate communication with stop. Otherwise, do not terminate transmission. This is useful if the user wishes to send a restart instead of a stop.
Returns
i2cMultiReturnValues
See also
Multi_I2CInit()
Multi_I2CReadBuf()

Variable Documentation

◆ I2C_SlaveRX_Callback

void(* I2C_SlaveRX_Callback) (uint8_t RX_Data)

If this callback is pointed to a function then it will be called when storing the data received from the master. This will bypass the circular buffer functions I2CRXAvail() and I2CGetByte() used when receiving data as a slave.

Parameters
RX_DataPasses the received data to the callback function

◆ I2C_SlaveTX_Callback

uint8_t(* I2C_SlaveTX_Callback) ()

If this callback is pointed to a function, then it will be called when retrieving the data to be sent to the master. This will bypass the circular buffer functions I2CTXAvail() and I2CFillSlaveTXBuf() used when transmitting data as a slave.

@ returns the data to be sent to the master