NetBurner 3.5.0
PDF Version |
|
Functions | |
void | MultiChannel_I2CInit (int moduleNum=DEFAULT_I2C_MODULE, uint8_t slave_Addr=0x08, uint8_t freqdiv=0x3C) |
Initialize the I2C peripheral module. | |
uint8_t | MultiChannel_I2CSendBuf (int moduleNum, uint8_t addr, puint8_t buf, int num, bool stop=true) |
Send a buffer of bytes to an I2C device. | |
uint8_t | MultiChannel_I2CReadBuf (int moduleNum, uint8_t addr, puint8_t buf, int num, bool stop=true) |
Read a number of bytes from an I2C device and store in the specified buffer. | |
void | I2CMultiChannelResetPeripheral (int moduleNum) |
Reset the specified I2C peripheral module. | |
uint8_t | MultiChannel_I2CRestart (int moduleNum, uint8_t addr, bool Read_Not_Write, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT) |
Restart communication with a I2C device. | |
uint8_t | MultiChannel_I2CStart (int moduleNum, uint8_t addr, bool Read_Not_Write, uint32_t ticks_to_wait=I2C_START_TIMEOUT) |
Send an I2C start to an I2C device to begin communication. | |
uint8_t | MultiChannel_I2CStop (int moduleNum=DEFAULT_I2C_MODULE, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT) |
Issue an I2C stop terminate communication with an I2C device and release the bus. | |
uint8_t | MultiChannel_I2CSend (int moduleNum, uint8_t val, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT) |
Send a single byte on the I2C bus. | |
uint8_t | MultiChannel_I2CRead (int moduleNum, puint8_t val, uint32_t ticks_to_wait=I2C_RX_TX_TIMEOUT) |
Read a single byte from the I2C bus. | |
Multichannel I2C Return Values | |
Function return values | |
#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. | |
Multichannel I2C Macros | |
I2C Macros | |
#define | I2C_SR_BUSY (((0x20 & I2C_SR) == 0x20)) |
Bus is busy (bit 5 of I2SR) | |
#define | I2C_CR_SLAVE (((0x20 & I2C_CR) == 0x00)) |
Bus set as slave (bit 5 of I2CR) | |
#define | I2C_SR_ARB_LOST (((0x10 & I2C_SR) == 0x10)) |
Bus arbitration was lost (bit 4 of I2SR) | |
#define | I2C_SR_ADRES_AS_SLAVE (((0x40 & I2C_SR) == 0x40)) |
Addressed as a slave (bit 6 of I2SR) | |
#define | I2C_SR_SLAVE_TX (((0x04 & I2C_SR) == 0x04)) |
State of read/write bit of the received address command (bit 2 of I2SR) | |
#define | I2C_CR_TX (((0x10 & I2C_CR) == 0x10)) |
Configured for transmit (bit 4 of I2CR) | |
#define | I2C_SR_RX_ACK (((0x01 & I2C_SR) == 0x00)) |
Received a RX ACK after last transmit (bit 0 of I2SR) | |
#define | I2C_CR_RX_ACK (((0x08 & I2C_CR) == 0x00)) |
Configured to RX Ack. | |
#define | I2C_SET_NO_ACK ((I2C_CR |= 0x08)) |
Configure I2C module not to send a RX ACK (bit 3 of I2CR) | |
#define | I2C_SET_ACK ((I2C_CR &= 0xF7)) |
Configure I2C module to send a RX ACK (bit 3 of I2CR) | |
#define | I2C_SET_TX ((I2C_CR |= 0x10)) |
Configure I2C module to be in TX mode (bit 4 of I2CR) | |
#define | I2C_SET_RX ((I2C_CR &= 0xEF)) |
Configure I2C module 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. | |
Supported platforms:
SB800EX
The platforms have multiple I2C interfaces called "modules". The available I2C modules available on a particular platform are determined by the connector configuration of that platform. Available I2C module numbers are defined below. Since the processor pins are multiplexed with many other functions, the modules chosen are not sequential. The default module number is 0.
I2C MODULE NUMBERS BY PLATFORM:
The most common I2C functions used are listed below. They automatically handle I2C start and stop conditions, as well as checking for I2C bus errors and recovery:
void I2CMultiChannelResetPeripheral | ( | int | moduleNum | ) |
#include <multichanneli2c.h>
Reset the specified I2C peripheral module.
Clears all interrupts, I2C conditions, and releases the bus.
moduleNum | I2C peripheral module number. |
void MultiChannel_I2CInit | ( | int | moduleNum = DEFAULT_I2C_MODULE, |
uint8_t | slave_Addr = 0x08, | ||
uint8_t | freqdiv = 0x3C ) |
#include <multichanneli2c.h>
Initialize the I2C peripheral module.
The frequency is based on the internal bus clock of the processor. The formula is: Freq = (250MHZ (sys clock)/2) / freqdiv to give max baud rate of the master mode I2C bus clock. Values for freqdiv are found in the i2fdr section of the NXP MCF5441x User Manual.
uint8_t MultiChannel_I2CRead | ( | int | moduleNum, |
puint8_t | val, | ||
uint32_t | ticks_to_wait = I2C_RX_TX_TIMEOUT ) |
#include <multichanneli2c.h>
Read a single byte from the I2C bus.
Reads a single byte from the I2C bus and stores it in val. A start or restart must have been previously issued to become the bus master, and a stop must be issued to release the bus when you are finished reading the desired number of bytes.
Does not handle no Ack of last byte, which needs to have a I2C_SET_NO_ACK called before the last read.
moduleNum | I2C peripheral module number. |
val | Location to store the byte read. |
ticks_to_wait | Amount of time to wait for a start transmission to complete, specified as system time ticks. The TICKS_PER_SECOND macro can be used with a multiplier or dividor. Includes the time to receive an ack from the I2C device. If not specified, the default time of I2C_RX_TX_TIMEOUT will be used. |
uint8_t MultiChannel_I2CReadBuf | ( | int | moduleNum, |
uint8_t | addr, | ||
puint8_t | buf, | ||
int | num, | ||
bool | stop = true ) |
#include <multichanneli2c.h>
Read a number of bytes from an I2C device and store in the specified buffer.
Sends an I2C start, reads the specified number of bytes into buf, and and finishes with our without an I2C stop (default is stop). If a stop is not issued, for purposes such as a restart, a stop must be called manually.
moduleNum | I2C peripheral module number. |
addr | I2C device address. |
buf | The buffer to store the data. |
num | The number of bytes to read. |
stop | Send a stop signal at the end of the transaction. If not specified, the default value is true. |
uint8_t MultiChannel_I2CRestart | ( | int | moduleNum, |
uint8_t | addr, | ||
bool | Read_Not_Write, | ||
uint32_t | ticks_to_wait = I2C_RX_TX_TIMEOUT ) |
#include <multichanneli2c.h>
Restart communication with a I2C device.
Restarts communication with an I2C device after completion of a read or write command in which a stop was not issued. Enables communicate on bus again without giving up control as the I2C bus master.
moduleNum | I2C peripheral module number. |
addr | I2C device address. |
Read_Not_Write | Specifies the next bus operation: true = read, false = write. |
ticks_to_wait | Amount of time to wait for a start transmission to complete, specified as system time ticks. The TICKS_PER_SECOND macro can be used with a multiplier or dividor. Includes the time to receive an ack from the I2C device. If not specified, the default time of I2C_RX_TX_TIMEOUT will be used. |
uint8_t MultiChannel_I2CSend | ( | int | moduleNum, |
uint8_t | val, | ||
uint32_t | ticks_to_wait = I2C_RX_TX_TIMEOUT ) |
#include <multichanneli2c.h>
Send a single byte on the I2C bus.
Sends a single byte on the I2C bus. A start or restart must have been previously issued to become the bus master, and a stop must be issued to release the bus when you are finished with writing the desired number of bytes.
moduleNum | I2C peripheral module number. |
val | Byte to send |
ticks_to_wait | Amount of time to wait for a start transmission to complete, specified as system time ticks. The TICKS_PER_SECOND macro can be used with a multiplier or dividor. Includes the time to receive an ack from the I2C device. If not specified, the default time of I2C_RX_TX_TIMEOUT will be used. |
uint8_t MultiChannel_I2CSendBuf | ( | int | moduleNum, |
uint8_t | addr, | ||
puint8_t | buf, | ||
int | num, | ||
bool | stop = true ) |
#include <multichanneli2c.h>
Send a buffer of bytes to an I2C device.
Sends an I2C start, the bytes in buf, and and finishes with our without an I2C stop (default is stop). If a stop is not issued, for purposes such as a restart, a stop must be called manually.
moduleNum | I2C peripheral module number. |
addr | I2C device address. |
buf | The buffer to send. |
num | The number of bytes in the buffer. |
stop | Send a stop signal at the end of transmission. If not specified, the default value is true. |
uint8_t MultiChannel_I2CStart | ( | int | moduleNum, |
uint8_t | addr, | ||
bool | Read_Not_Write, | ||
uint32_t | ticks_to_wait = I2C_START_TIMEOUT ) |
#include <multichanneli2c.h>
Send an I2C start to an I2C device to begin communication.
Restarts communication with an I2C device after completion of a read or write command in which a stop was not issued. Enables communicate on bus again without giving up control as the I2C bus master.
moduleNum | I2C peripheral module number. |
addr | I2C device address. |
Read_Not_Write | Specifies the next bus operation: true = read, false = write. |
ticks_to_wait | Amount of time to wait for a start transmission to complete, specified as system time ticks. The TICKS_PER_SECOND macro can be used with a multiplier or dividor. Includes the time to receive an ack from the I2C device. If not specified, the default time of I2C_START_TIMEOUT will be used. |
uint8_t MultiChannel_I2CStop | ( | int | moduleNum = DEFAULT_I2C_MODULE, |
uint32_t | ticks_to_wait = I2C_RX_TX_TIMEOUT ) |
#include <multichanneli2c.h>
Issue an I2C stop terminate communication with an I2C device and release the bus.
Terminate any communication and release the I2C bus.
moduleNum | I2C peripheral module number. |
ticks_to_wait | Amount of time to wait for a start transmission to complete, specified as system time ticks. The TICKS_PER_SECOND macro can be used with a multiplier or dividor. Includes the time to receive an ack from the I2C device. If not specified, the default time of I2C_RX_TX_TIMEOUT will be used. |