NetBurner 3.0
i2cmulti.h File Reference

NetBurner Real-Time Operating System API. More...

#include <basictypes.h>
#include <nbrtos.h>
#include <sim.h>

Go to the source code of this file.

Macros

#define I2C_MAX_BUF_SIZE   (64)
 Size allocated to input and output buffers in slave mode I2C.
 
#define I2C_RX_TX_TIMEOUT   (5)
 Ticks allowed before timeout of a single byte transmission.
 
#define I2C_START_TIMEOUT   (20)
 Ticks allowed before timeout when attempting start on I2C bus.
 
#define I2C_SLAVE_TX_TERM_CHAR   (0)
 Terminating char to be sent when Slave TX buffer is empty.
 
#define I2C_OK   (0)
 Last instruction terminated correctly.
 
#define I2C_NEXT_WRITE_OK   (1)
 I2C bus is OK for a write.
 
#define I2C_NEXT_READ_OK   (2)
 I2C bus is OK for a read.
 
#define I2C_MASTER_OK   (3)
 I2C finished transmission but still owns but (need to stop or restart)
 
#define I2C_TIMEOUT   (4)
 A timeout occurred while trying communicate on I2C bus.
 
#define I2C_BUS_NOT_AVAIL   (5)
 A timeout occurred while trying gain I2C bus control.
 
#define I2C_NOT_READY   (6)
 A read or write was attempted before I2C ready or during a slave transmission.
 
#define I2C_LOST_ARB   (7)
 Lost arbitration during start.
 
#define I2C_LOST_ARB_ADD   (8)
 Lost arbitration and then winner addressed our slave address.
 
#define I2C_NO_LINK_RX_ACK   (9)
 We are in Master TX mode and received no ACK from slave device, possibly during start.
 
#define I2CInit   Multi_I2CInit
 Calls Muti_I2CInit.
 
#define I2CSendBuf   Multi_I2CSendBuf
 Calls Muti_I2CSendBuf.
 
#define I2CReadBuf   Multi_I2CReadBuf
 Calls Muti_I2CReadBuf.
 
#define I2CRestart   Multi_I2CRestart
 Calls Muti_I2CRestart.
 
#define I2CStart   Multi_I2CStart
 Calls Muti_I2CStart.
 
#define I2CStop   Multi_I2CStop
 Calls Muti_I2CStrop.
 
#define I2CSend   Multi_I2CSend
 Calls Muti_I2CSend.
 
#define I2CRead   Multi_I2CRead
 Calls Muti_I2CRead.
 
#define I2CResetPeripheral   Multi_ResetPeripheral
 Calls Multi_ResetPeripheral.
 
#define I2C_START_READ   (1)
 Read option to be used for bRead_Not_Write.
 
#define I2C_START_WRITE   (0)
 Write option to be used for bRead_Not_Write.
 
#define I2C_SR_BUSY   (((0x20 & I2C_SR) == 0x20))
 Is I2C bus busy (bit 5 of I2SR)
 
#define I2C_CR_SLAVE   (((0x20 & I2C_CR) == 0x00))
 Is I2C bus set as slave (bit 5 of I2CR)
 
#define I2C_SR_ARB_LOST   (((0x10 & I2C_SR) == 0x10))
 Was I2C bus Arbitration Lost (bit 4 of I2SR)
 
#define I2C_SR_ADRES_AS_SLAVE   (((0x40 & I2C_SR) == 0x40))
 Was Device addressed as a slave(bit 6 of I2SR)
 
#define I2C_SR_SLAVE_TX   (((0x04 & I2C_SR) == 0x04))
 Was Device addressed as a slave for TX (bit 2 of I2SR)
 
#define I2C_CR_TX   (((0x10 & I2C_CR) == 0x10))
 Are we configured for TX (bit 4 of I2CR)
 
#define I2C_SR_RX_ACK   (((0x01 & I2C_SR) == 0x00))
 Did we receive an RX ACK after last transmit (bit 0 of I2SR)
 
#define I2C_CR_RX_ACK   (((0x08 & I2C_CR) == 0x00))
 Are we set to RX ACK.
 
#define I2C_SET_NO_ACK   ((I2C_CR |= 0x08))
 Configure I2C not to send a RX ACK (bit 3 of I2CR)
 
#define I2C_SET_ACK   ((I2C_CR &= 0xF7))
 Configure I2C to send a RX ACK (bit 3 of I2CR)
 
#define I2C_SET_TX   ((I2C_CR |= 0x10))
 Configure I2C to be in TX mode (bit 4 of I2CR)
 
#define I2C_SET_RX   ((I2C_CR &= 0xEF))
 Configure I2C to be in RX mode (bit 4 of I2CR)
 
#define I2C_SET_REPEAT_START   ((I2C_CR |= 0x04))
 Configure I2C to send a repeated start signal.
 
#define I2C_CLR_ARB_LOST   ((I2C_SR &= 0xEF))
 Clear Arbitration lost error condition.
 

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...
 
uint8_t Multi_I2CStart (uint8_t addr, bool Read_Not_Write, uint32_t ticks_to_wait=I2C_START_TIMEOUT)
 This function is used to obtain an I2C bus and start communication in master mode. More...
 
uint8_t Multi_I2CStop (uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
 This function ends communication and releases control of the I2C bus. This function puts your NetBurner board into idle/slave mode. More...
 
uint8_t Multi_I2CSend (uint8_t val, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
 This function sends a single byte in master mode on the I2C bus. More...
 
uint8_t Multi_I2CRead (puint8_t val, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT)
 This function reads a single byte in master mode from the I2C 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

NetBurner Real-Time Operating System API.