PIC24 Support Libraries
Functions
pic24_i2c.c File Reference
#include "pic24_i2c.h"
#include <stdio.h>
#include "pic24_util.h"
#include "pic24_clockfreq.h"

Go to the source code of this file.

Functions

void configI2C1 (uint16_t u16_FkHZ)
 
void startI2C1 (void)
 
void rstartI2C1 (void)
 
void stopI2C1 (void)
 
void putI2C1 (uint8_t u8_val)
 
uint8_t putNoAckCheckI2C1 (uint8_t u8_val)
 
uint8_t getI2C1 (uint8_t u8_ack2Send)
 
void write1I2C1 (uint8_t u8_addr, uint8_t u8_d1)
 
void write2I2C1 (uint8_t u8_addr, uint8_t u8_d1, uint8_t u8_d2)
 
void writeNI2C1 (uint8_t u8_addr, uint8_t *pu8_data, uint16_t u16_cnt)
 
void read1I2C1 (uint8_t u8_addr, uint8_t *pu8_d1)
 
void read2I2C1 (uint8_t u8_addr, uint8_t *pu8_d1, uint8_t *pu8_d2)
 
void readNI2C1 (uint8_t u8_addr, uint8_t *pu8_data, uint16_t u16_cnt)
 

Detailed Description

I2C support functions.

See also
pic24_i2c.h for details.

Definition in file pic24_i2c.c.

Function Documentation

◆ configI2C1()

void configI2C1 ( uint16_t  u16_FkHZ)

Configure and enable the I2C1 module for operation at u16_FkHZ kHZ clock speed.

Parameters
u16_FkHZspecifies clock speed in kHZ

Definition at line 51 of file pic24_i2c.c.

◆ getI2C1()

uint8_t getI2C1 ( uint8_t  u8_ack2Send)

Operation: Wait for a byte byte on the I2C bus, send u8_ack2Send as the acknowledgement bit to send back to the slave.

Parameters
u8_ack2Sendack bit to send back to slave after byte is read
Returns
byte read from slave

Definition at line 159 of file pic24_i2c.c.

◆ putI2C1()

void putI2C1 ( uint8_t  u8_val)

Operation: Send one byte (u8_val), if NAK is returned use reportError() function to save error and do software reset.

Parameters
u8_valbyte to send

Definition at line 119 of file pic24_i2c.c.

Referenced by read1I2C1(), read2I2C1(), readNI2C1(), write1I2C1(), write2I2C1(), and writeNI2C1().

◆ putNoAckCheckI2C1()

uint8_t putNoAckCheckI2C1 ( uint8_t  u8_val)

Operation: Send one byte (u8_val), return the acknowledgement bit that comes back from the slave. This function does not error out if a NAK is returned.

Parameters
u8_valbyte to send
Returns
Ack bit value returned from slave.

Definition at line 141 of file pic24_i2c.c.

◆ read1I2C1()

void read1I2C1 ( uint8_t  u8_addr,
uint8_t pu8_d1 
)

Transaction: Read one byte from I2C slave at address u8_addr, save to *pu8_d1. As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
pu8_d1Pointer to location to store byte read from slave

Definition at line 227 of file pic24_i2c.c.

◆ read2I2C1()

void read2I2C1 ( uint8_t  u8_addr,
uint8_t pu8_d1,
uint8_t pu8_d2 
)

Transaction: Read two bytes from I2C slave at address u8_addr, save to *pu8_d1, *pu8_d2. As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
pu8_d1Pointer to location to store first byte read from slave
pu8_d2Pointer to location to store second byte read from slave

Definition at line 240 of file pic24_i2c.c.

◆ readNI2C1()

void readNI2C1 ( uint8_t  u8_addr,
uint8_t pu8_data,
uint16_t  u16_cnt 
)

Transaction: Read u16_cnt bytes from I2C slave at address u8_addr, save to buffer *pu8_data. As per the I2C standard, a NAK is returned for the last byte read from the slave, ACKs are returned for the other bytes.

Parameters
u8_addrSlave I2C address
pu8_dataPointer to buffer for storing bytes read from slave
u16_cntNumber of bytes read from slave.

Definition at line 254 of file pic24_i2c.c.

◆ rstartI2C1()

void rstartI2C1 ( void  )

Operation: Perform an I2C repeated start operation.

Definition at line 86 of file pic24_i2c.c.

◆ startI2C1()

void startI2C1 ( void  )

Operation: Perform an I2C start operation.

Definition at line 70 of file pic24_i2c.c.

Referenced by read1I2C1(), read2I2C1(), readNI2C1(), write1I2C1(), write2I2C1(), and writeNI2C1().

◆ stopI2C1()

void stopI2C1 ( void  )

Operation: Perform an I2C stop operation.

Definition at line 102 of file pic24_i2c.c.

◆ write1I2C1()

void write1I2C1 ( uint8_t  u8_addr,
uint8_t  u8_d1 
)

Transaction: Write 1 byte (u8_d1) to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
u8_d1Byte to send

Definition at line 185 of file pic24_i2c.c.

◆ write2I2C1()

void write2I2C1 ( uint8_t  u8_addr,
uint8_t  u8_d1,
uint8_t  u8_d2 
)

Transaction: Write 2 bytes (u8_d1, u8_d2) to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
u8_d1First byte to send
u8_d2Second byte to send

Definition at line 197 of file pic24_i2c.c.

◆ writeNI2C1()

void writeNI2C1 ( uint8_t  u8_addr,
uint8_t pu8_data,
uint16_t  u16_cnt 
)

Transaction: Write u16_cnt bytes stored in buffer *pu8_data to I2C slave at address u8_addr.

Parameters
u8_addrSlave I2C address
pu8_dataPointer to buffer containing bytes to send
u16_cntNumber of bytes to send

Definition at line 211 of file pic24_i2c.c.