293
USCI I2C – Interfacing BH1750 Ambient Light Sensor
Using USCI in I2C mode is a bit difficult compared to using USCI in SPI mode. This is because of the
many iterations and function calls in I2C mode. Again, here I tried to keep things simple and kept things
in a fashion we would normally expect. USCI-based I2C can be realized with a state-of-machine too
but that way is not easy for beginners.
Code Example
HW_I2C.h
#include <msp430.h>
void I2C_USCI_init(unsigned char address);
void I2C_USCI_set_address(unsigned char address);
unsigned char I2C_USCI_read_byte(unsigned char address);
unsigned char I2C_USCI_read_word(unsigned char address,unsigned char *value,
unsigned char length);
unsigned char I2C_USCI_write_byte(unsigned char address, unsigned char value);