Sensor Watch 0.0.2
A board replacement for the classic Casio F-91W wristwatch, powered by a Microchip SAM L22 microcontroller.
Loading...
Searching...
No Matches
Functions
I2C Controller Driver

This section covers functions related to the SAM L22's built-I2C driver, including configuring the I2C bus, putting values directly on the bus and reading data from registers on I2C devices. More...

Functions

void watch_enable_i2c (void)
 Enables the I2C peripheral. Call this before attempting to interface with I2C devices.
 
void watch_disable_i2c (void)
 Disables the I2C peripheral.
 
void watch_i2c_send (int16_t addr, uint8_t *buf, uint16_t length)
 Sends a series of values to a device on the I2C bus.
 
void watch_i2c_receive (int16_t addr, uint8_t *buf, uint16_t length)
 Receives a series of values from a device on the I2C bus.
 
void watch_i2c_write8 (int16_t addr, uint8_t reg, uint8_t data)
 Writes a byte to a register in an I2C device.
 
uint8_t watch_i2c_read8 (int16_t addr, uint8_t reg)
 Reads a byte from a register in an I2C device.
 
uint16_t watch_i2c_read16 (int16_t addr, uint8_t reg)
 Reads an unsigned little-endian word from a register in an I2C device.
 
uint32_t watch_i2c_read24 (int16_t addr, uint8_t reg)
 Reads three bytes as an unsigned little-endian int from a register in an I2C device.
 
uint32_t watch_i2c_read32 (int16_t addr, uint8_t reg)
 Reads an unsigned little-endian int from a register in an I2C device.
 

Detailed Description

This section covers functions related to the SAM L22's built-I2C driver, including configuring the I2C bus, putting values directly on the bus and reading data from registers on I2C devices.

Function Documentation

◆ watch_i2c_read16()

uint16_t watch_i2c_read16 ( int16_t  addr,
uint8_t  reg 
)

Reads an unsigned little-endian word from a register in an I2C device.

Parameters
addrThe address of the device you wish to address.
regThe register on the device that you wish to read.
Returns
An unsigned word representing the value of the register that was read.
Note
This reads two bytes into the word in bus order. If the device returns the LSB first and then the MSB, you can use this value as returned. If the device returns the data in big-endian order or uses some other kind of fancy bit packing, you may need to shuffle some bits around.

◆ watch_i2c_read24()

uint32_t watch_i2c_read24 ( int16_t  addr,
uint8_t  reg 
)

Reads three bytes as an unsigned little-endian int from a register in an I2C device.

Parameters
addrThe address of the device you wish to address.
regThe register on the device that you wish to read.
Returns
An unsigned word representing the value of the register that was read.
Note
This reads three bytes into the word in bus order. If the device returns these bytes LSB first, you can use this value as returned. If there is a sign bit, the device returns the data in big-endian order, or it uses some other kind of fancy bit packing, you may need to shuffle some bits around.

◆ watch_i2c_read32()

uint32_t watch_i2c_read32 ( int16_t  addr,
uint8_t  reg 
)

Reads an unsigned little-endian int from a register in an I2C device.

Parameters
addrThe address of the device you wish to address.
regThe register on the device that you wish to read.
Returns
An unsigned word representing the value of the register that was read.
Note
This reads three bytes into the word in bus order. If the device returns these bytes LSB first, you can use this value as returned. If the device returns the data in big-endian order, or it uses some other kind of fancy bit packing, you may need to shuffle some bits around.

◆ watch_i2c_read8()

uint8_t watch_i2c_read8 ( int16_t  addr,
uint8_t  reg 
)

Reads a byte from a register in an I2C device.

Parameters
addrThe address of the device you wish to address.
regThe register on the device that you wish to read.
Returns
An unsigned byte representing the value of the register that was read.

◆ watch_i2c_receive()

void watch_i2c_receive ( int16_t  addr,
uint8_t *  buf,
uint16_t  length 
)

Receives a series of values from a device on the I2C bus.

Parameters
addrThe address of the device you wish to hear from.
bufStorage for the incoming bytes; on return, it will contain the received data.
lengthThe number of bytes that you wish to receive.

◆ watch_i2c_send()

void watch_i2c_send ( int16_t  addr,
uint8_t *  buf,
uint16_t  length 
)

Sends a series of values to a device on the I2C bus.

Parameters
addrThe address of the device you wish to talk to.
bufA series of unsigned bytes; the data you wish to transmit.
lengthThe number of bytes in buf that you wish to send.

◆ watch_i2c_write8()

void watch_i2c_write8 ( int16_t  addr,
uint8_t  reg,
uint8_t  data 
)

Writes a byte to a register in an I2C device.

Parameters
addrThe address of the device you wish to address.
regThe register on the device that you wish to set.
dataThe value that you wish to set the register to.