예제 #1
0
uint8 hal_dev_mag3110_read_reg(uint8 addr)
{
    uint8 result;

    i2c_start(I2C_MAG);
    i2c_write_byte(I2C_MAG, MAG3110_I2C_ADDRESS | I2C_WRITE);
    
    i2c_wait(I2C_MAG);
    i2c_get_ack(I2C_MAG);

    i2c_write_byte(I2C_MAG, addr);
    i2c_wait(I2C_MAG);
    i2c_get_ack(I2C_MAG);

    i2c_repeated_start(I2C_MAG);
    i2c_write_byte(I2C_MAG, MAG3110_I2C_ADDRESS | I2C_READ);
    i2c_wait(I2C_MAG);
    i2c_get_ack(I2C_MAG);

    i2c_set_rx_mode(I2C_MAG);

    i2c_give_nack(I2C_MAG);
    result = i2c_read_byte(I2C_MAG);
    i2c_wait(I2C_MAG);

    i2c_stop(I2C_MAG);
    result = i2c_read_byte(I2C_MAG);
    pause();
    return result;
}
예제 #2
0
uint8_t I2C_ReadOneByte(uint8_t SlaveAddr, uint8_t RegAddr)
{
    uint8_t result;

    i2c_start(I2C0_B);
    i2c_write_byte(I2C0_B, (SlaveAddr<<1) | I2C_WRITE);
    
    i2c_wait(I2C0_B);
    i2c_get_ack(I2C0_B);

    i2c_write_byte(I2C0_B, RegAddr);
    i2c_wait(I2C0_B);
    i2c_get_ack(I2C0_B);

    i2c_repeated_start(I2C0_B);
    i2c_write_byte(I2C0_B, (SlaveAddr<<1) | I2C_READ);
    i2c_wait(I2C0_B);
    i2c_get_ack(I2C0_B);

    i2c_set_rx_mode(I2C0_B);

    i2c_give_nack(I2C0_B);
    result = i2c_read_byte(I2C0_B);
    i2c_wait(I2C0_B);

    i2c_stop(I2C0_B);
    result = i2c_read_byte(I2C0_B);
    pause(40);
    return result;
}
예제 #3
0
파일: i2c.c 프로젝트: cculpepper/widebandO2
uint8_t i2cFlashRead(uint16_t addr, int numBytes, char *dataPtr){
	int ret;
	int index;
	index = 0; 
	numBytes--;
	i2c_start(intI2c);
	ret = i2c_write(intI2c, i2cFlashAddr | I2C_WRITE);
	//if (ret) return 1;
	ret = i2c_write(intI2c, ((addr) >> 8));// upper byte first
	//if (ret) return 1;
	ret = i2c_write(intI2c, ((addr) & 0xFF));
	//if (ret) return 1;
	i2c_repeated_start(intI2c);
	i2c_write(intI2c, i2cFlashAddr | I2C_READ); // Send the read. 
	i2c_set_rx(intI2c);
	dataPtr[0] = i2c_read(intI2c); // Dummy read 
	i2c_wait(intI2c);
	while (numBytes--){
		
		dataPtr[index++] = i2c_read(intI2c);
		i2c_give_ack(intI2c);
		i2c_wait(intI2c);
	}
	dataPtr[index++] = i2c_read(intI2c);
	i2c_give_nack(intI2c);
	i2c_stop(intI2c);
	return index;
}
예제 #4
0
uint8_t mma8451_read(uint8_t addr)
{
    delay(1);
    i2c_start(I2C0_B);
    i2c_write(I2C0_B, MMA8451_I2C_ADDRESS | I2C_WRITE);
    i2c_write(I2C0_B, addr);
    i2c_repeated_start(I2C0_B);
    i2c_write(I2C0_B, MMA8451_I2C_ADDRESS | I2C_READ);
    i2c_set_rx(I2C0_B);
    i2c_give_nack(I2C0_B);
    i2c_read(I2C0_B);
    i2c_wait(I2C0_B);
    i2c_stop(I2C0_B);
    return i2c_read(I2C0_B);
}
예제 #5
0
파일: mag3110.c 프로젝트: Vinhuit/Freescale
uint8_t mag3110_read(uint8_t addr)
{
	  i2c_delay();
    i2c_start(I2C0);
    i2c_write(I2C0, MAG3110_I2C_ADDR | I2C_WRITE);
    i2c_write(I2C0, addr);
    i2c_repeated_start(I2C0);
    i2c_write(I2C0, MAG3110_I2C_ADDR | I2C_READ);
    i2c_set_rx(I2C0);
    i2c_give_nack(I2C0);
    i2c_read(I2C0);
    i2c_wait(I2C0);
    i2c_stop(I2C0);
    return i2c_read(I2C0);
}
예제 #6
0
uint8_t mma8451_read(uint8_t addr)
{
    short n;
    for(n=0; n<100; n++)
        asm("nop");

    i2c_start(I2C0_B);
    i2c_write(I2C0_B, MMA8451_I2C_ADDRESS | I2C_WRITE);
    i2c_write(I2C0_B, addr);
    i2c_repeated_start(I2C0_B);
    i2c_write(I2C0_B, MMA8451_I2C_ADDRESS | I2C_READ);
    i2c_set_rx(I2C0_B);
    i2c_give_nack(I2C0_B);
    i2c_read(I2C0_B);
    i2c_wait(I2C0_B);
    i2c_stop(I2C0_B);
    return i2c_read(I2C0_B);
}
예제 #7
0
uint8 hal_dev_mma8451_read_reg(uint8 addr)
{
    uint8 result;
    int i;  
	
    i2c_start(I2C0_B);
    i2c_write_byte(I2C0_B, MMA8451_I2C_ADDRESS | I2C_WRITE);
    
    i2c_wait(I2C0_B);
    i2c_get_ack(I2C0_B);

    i2c_write_byte(I2C0_B, addr);
    i2c_wait(I2C0_B);
    i2c_get_ack(I2C0_B);

    i2c_repeated_start(I2C0_B);
		for(i=0;i<1000;i++)
       for( i=0;i<1000;i++);
	
    i2c_write_byte(I2C0_B, MMA8451_I2C_ADDRESS | I2C_READ);
    i2c_wait(I2C0_B);
    i2c_get_ack(I2C0_B);

    i2c_set_rx_mode(I2C0_B);

    i2c_give_nack(I2C0_B);
    result = i2c_read_byte(I2C0_B);
    i2c_wait(I2C0_B);

    i2c_stop(I2C0_B);
    result = i2c_read_byte(I2C0_B);
    pause();
		for(i=0;i<1000;i++)
       for( i=0;i<1000;i++);
    return result;
}