コード例 #1
0
ファイル: pic24_i2c.c プロジェクト: daudzoss/2048
/**
Transaction: Read two bytes from I2C slave at address \em u8_addr, save to \em *pu8_d1, \em *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.
\param u8_addr  Slave I2C address
\param pu8_d1 Pointer to location to store first byte read from slave
\param pu8_d2 Pointer to location to store second byte read from slave
*/
void read2I2C1 (uint8 u8_addr,uint8* pu8_d1, uint8* pu8_d2) {
  startI2C1();
  putI2C1(I2C_RADDR(u8_addr));
  *pu8_d1 = getI2C1(I2C_ACK);
  *pu8_d2 = getI2C1(I2C_NAK);
  stopI2C1();
}
コード例 #2
0
ファイル: pic24_i2c.c プロジェクト: daudzoss/2048
/**
Transaction: Read \em u16_cnt bytes from I2C slave at address \em u8_addr, save to buffer \em *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.
\param u8_addr  Slave I2C address
\param pu8_data Pointer to buffer for storing bytes read from slave
\param u16_cnt Number of bytes read from slave.
*/
void readNI2C1 (uint8 u8_addr,uint8* pu8_data, uint16 u16_cnt) {
  uint16 u16_i;
  startI2C1();
  putI2C1(I2C_RADDR(u8_addr));
  for (u16_i=0; u16_i < u16_cnt; u16_i++) {
    if (u16_i != u16_cnt-1) *pu8_data = getI2C1(I2C_ACK);
    else *pu8_data = getI2C1(I2C_NAK);
    pu8_data++;
  }
  stopI2C1();
}
コード例 #3
0
ファイル: pic24_i2c.c プロジェクト: daudzoss/2048
/**
Transaction: Read one byte from I2C slave at address \em u8_addr, save to \em *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.
\param u8_addr  Slave I2C address
\param pu8_d1 Pointer to location to store byte read from slave
*/
void read1I2C1 (uint8 u8_addr,uint8* pu8_d1) {
  startI2C1();
  putI2C1(I2C_RADDR(u8_addr));
  *pu8_d1 = getI2C1(I2C_NAK); //last ack bit from master to slave during read must be a NAK
  stopI2C1();
}
コード例 #4
0
ファイル: 30-Oct.c プロジェクト: bjones1/ece3724_inclass
uint8_t putNoAckCheckI2C1(uint8_t u8_val);

// First transaction
// =================
startI2C1();
putI2C1(0x12);
// 165: Read or write? Answer R, W, X. Address was 0x12:
//
// =========  ==============================
// 0001 001   0
// Address    |R/W not| bit = 0 means write.
// =========  ==============================
//
// .. |R/W not| replace:: :math:`R/\overline{W}`
//
// 166: Write the byte 0x34.
putI2C1(0x34);
stopI2C1();
//
// Second transaction
// ==================
startI2C1();
putI2C1(0x13);
// 167: Read a byte into u8_x. Acknowledge, since we're reading more data.
u8_x=getI2C1(0);
// 168: Read a byte into u8_y. No acknowledge, since we're done reading data.
u8_y=getI2C1(1);
stopI2C1();

// Next time: use the MS5607.