Example #1
0
//read a byte from the eeprom
BYTE readEEPROM(BYTE address){
    i2cStart(I2C2);
    i2cSendByte(I2C2, 0x50 << 1);
    i2cSendByte(I2C2, (address & 0xFF00)>> 8);
    i2cSendByte(I2C2, address & 0xFF);
    i2cRepeatedStart(I2C2);
    i2cSendByte(I2C2, 0x50 << 1 | 0x01);
    BYTE temp = i2cRecieveByte(I2C2, FALSE);
    i2cStop(I2C2);
    return temp;
}
Example #2
0
//Need to implement a check here so that it doesn't get stuck if the PSOC isn't attached
void PSOC_Read(){
    //First 12 bytes are current sensor data, next 8 bytes are shock pots
    BYTE PSOC_Data[24];
    int i;
    i2cStart(I2C1);
    i2cSendByte(I2C1, (0x08 << 1) + 0) ;//send addresss and write
    i2cSendByte(I2C1, 0x00);//send data pointer
    i2cRepeatedStart(I2C1); //Repeat start to change data direction

  //  i2cStart(I2C1);
    i2cSendByte(I2C1, (0x08 << 1) + 1) ;//send addresss and read
    for(i = 0 ; i < 23; i++){
        PSOC_Data[i] = i2cRecieveByte(I2C1, TRUE);
    }
    PSOC_Data[23] = i2cRecieveByte(I2C1, FALSE);
    i2cStop(I2C1);//Stop the bus
    //Combine the bytes
    for(i = 0; i<12; i++){
    PSOC_volts[i] = (PSOC_Data[2*i+1] <<8  | PSOC_Data[2*i]);
    }
 }
Example #3
0
//read multiple bytes from the eeprom
BOOL readMultiEEPROM(BYTE address, BYTE *data, int length){
    BOOL keepReading = TRUE;
    i2cStart(I2C2);
    i2cSendByte(I2C2, 0x50 << 1);
    i2cSendByte(I2C2, (address & 0xFF00)>> 8);
    i2cSendByte(I2C2, address & 0xFF);
    i2cRepeatedStart(I2C2);
    i2cSendByte(I2C2, 0x50 << 1 | 0x01);
    int i;
    for(i = 0; i < length-1; i++){
        *(data + i) = i2cRecieveByte(I2C2, TRUE);
        if(*(data+i)  == 0xFF){
            keepReading = FALSE;
        }
        if(keepReading == FALSE){
            *(data +i) = 0xFF;
        }
    }
    *(data + length - 1) = i2cRecieveByte(I2C2, FALSE);
    i2cStop(I2C2);
    return keepReading;
}
Example #4
0
File: i2c.c Project: ninux/mc
 /**
 * Liest Daten von einem I2C-Gerät dass zusätzlich ein 
 * Befehls-Byte benötigt.
 *
 * @param [in] adr
 *      die I2C-Adresse des gewünschten Gerätes
 * @param [in] cmd
 *      der gewünschte Befehl (Laut Datenblatt vom Slave)
 * @param [out] data
 *      die zu sendenden Daten
 * @param [in] length
 *      die Anzahl Bytes, die gesendet werden.
 *
 * @return
 *      EC_SUCCESS          falls der Slave immer mit ACK geantwortet hat    
 *      EC_I2C_NAK          falls kein ACK empf. wurde.
 *      EC_I2C_NO_ANSWER    falls I2C-Gerät nicht geantwortet hat
 */
tError i2cReadCmdData(uint8 adr, uint8 cmd, uint8 *data, uint8 length)
{
  tError result;

  // @ToDo implement function code
  result = i2cStart(adr, TRUE);		// init communication for write
  if (result != EC_SUCCESS) {
	  return result;
  }
  
  result = i2cSendByte(cmd);		// send the command byte
  if (result != EC_SUCCESS) {
	  return result;
  }
  
  i2cRepeatedStart(adr, FALSE);		// generate repeated start
  if (result != EC_SUCCESS) {
	  return result;
  }
  
  i2cReceiveData(data, length);		// read the data 
  return EC_SUCCESS;
}