Example #1
0
bool eeprom_read(uint32_t address, void* data, uint16_t length)
{
    uint8_t control[3];
    control[0] = (uint8_t)(0xa0 | 0 | 0); // clear read/write bit
    control[1] = (uint8_t)(address >> 8);
    control[2] = (uint8_t)address;
    
    if (address > 0xffff){
        control[0] |= 0x08;
    }

    iic_start(EEPROM_IIC_CHANNEL);
    
    if (iic_write(EEPROM_IIC_CHANNEL, control, 3) == false){
        iic_stop(EEPROM_IIC_CHANNEL);
        return false;
    }

    iic_repeated_start(EEPROM_IIC_CHANNEL);
    
    control[0] |= 1; // set read/write bit
    
    if (iic_write(EEPROM_IIC_CHANNEL, control, 1) == false){
        iic_stop(EEPROM_IIC_CHANNEL);
        return false;
    }

    iic_read(EEPROM_IIC_CHANNEL, data, length);
    
    iic_stop(EEPROM_IIC_CHANNEL);
    
    return true;
}
void ads_point_reg(void)
{
	unsigned char Initdata[4]={0};

	/* address and write command */
	Initdata[0] =0x90;
	/* point register */
	Initdata[1] =0x00;

#if 1
	unsigned char i=0;
	SDA_OUT;
	start();
	for(i=0;i<2;i++)
	{
		iic_write_m(Initdata[i]);
	}

	/* IIC_write(Initdata, 0, 16); */

	stop();
#else
	iic_write(Initdata[0], &Initdata[1], 1);
#endif
}
Example #3
0
int main(int argc, char *argv[])
{
    int status;

    /* Read buffer to hold the data */
    char *buffer = (char *)malloc(EEPROMSIZE * sizeof(char));

    char data[] = "THIS IS A TEST MESSAGE FOR THE I2C PROTOCOL COMMUNICATION WITH A EEPROM. IT WAS WRITTEN FOR A REDPITAYA MEASURMENT TOOL.";
    size_t size = strlen(data);

    /* Sample offset inside an eeprom */
    int offset = 0x100;

    /*
     * Open the device.
     */
    fd = open("/dev/i2c-0", O_RDWR);

    if(fd < 0)
    {
        printf("Cannot open the IIC device\n");
        return 1;
    }

    status = ioctl(fd, I2C_SLAVE_FORCE, EEPROM_ADDR);
    if(status < 0)
    {
        printf("Unable to set the EEPROM address\n");
        return -1;
    }

    /* Write to redpitaya eeprom */
    status = iic_write((char *)data, offset, size);
    if(status) {
        fprintf(stderr, "Cannot Write to EEPROM\n");
        close(fd);
        return -1;
    }

    /* Read from redpitaya eeprom */
    status = iic_read(buffer, EEPROM_ADDR, EEPROMSIZE);
    if (status)
    {
        printf("Cannot Read from EEPROM \n");
        close(fd);
        return 1;
    }

    printf("eerprom test successfull.\n");

    /* Release allocations */
    close(fd);
    free(buffer);

    return 0;
}
Example #4
0
/*----------------------------------------------------------------------------*/
void write_eerom(u16 addr,u8 dat)
{
     u8 iic_addr=0,page=0;
	 
    iic_addr=EEPROM_Addr_Align(addr);
    page =EEPROM_Addr_to_Page(addr);
	
    iic_write((0xa0|page),iic_addr,&dat,1);
    delay_10ms(2);
}
Example #5
0
static bool eeprom_page_write(uint32_t address, void* data, uint8_t length)
{
    uint8_t control[3];
    uint16_t timeout = WRITE_TIMEOUT;
    control[0] = (uint8_t)(0xa0 | 0 | 0);
    control[1] = (uint8_t)(address >> 8);
    control[2] = (uint8_t)address;
    
    if (address > 0xffff){
        control[0] |= 0x08;
    }

    iic_start(EEPROM_IIC_CHANNEL);
    
    if (iic_write(EEPROM_IIC_CHANNEL, control, 3) == false){
        iic_stop(EEPROM_IIC_CHANNEL);
        return false;
    }

    if (iic_write(EEPROM_IIC_CHANNEL, data, length) == false){
        iic_stop(EEPROM_IIC_CHANNEL);
        return false;
    }

    iic_stop(EEPROM_IIC_CHANNEL);
    
    while (timeout--){
        iic_start(EEPROM_IIC_CHANNEL);
        if (iic_write(EEPROM_IIC_CHANNEL, control, 1)){
            iic_stop(EEPROM_IIC_CHANNEL);
            return true;
        }
        iic_stop(EEPROM_IIC_CHANNEL);
    }
    
    return false;
}
void ads_confige(unsigned int channel)
{
	SysCtlPeripheralEnable(IIC_PERIPH);
	SDA_Out;
	SCL_Out;
	SCL_H;
	SDA_H;

	unsigned char Initdata[4]={0};

	switch (channel) {
		case 0:
			Initdata[2] = 0xc2;
			break;
		case 1:
			Initdata[2] = 0xd2;
			break;
		case 2:
			Initdata[2] = 0xe2;
			break;
		case 3:
			Initdata[2] = 0xf2;
			break;
		default:
			break;
	}


	/* address and write command */
	Initdata[0] =0x90;
	/* point register */
	Initdata[1] =0x01;
	Initdata[3] =0xe3;
	/* Initdata[3] =0x03; // 配置字低字节 */

#if 1
	unsigned char i=0;
	start();
	for(i=0;i<4;i++) {
		iic_write_m(Initdata[i]);
	}

	stop();
#else
	iic_write(Initdata[0], &Initdata[1], 3);
#endif
}
Example #7
0
int main( void )
{ 
    unsigned char buf[4];

    alt_putstr("Boot\n");

    // I2C Clock Setting
    IOWR( IIC_0_BASE, 1,  42 ); // 100kHz (50,000kHz / 100kHz / 12 = 41.6...)
//  IOWR( IIC_0_BASE, 1,  11 ); // 400kHz (50,000kHz / 400kHz / 12 = 10.4...)

    buf[0] = 0;
    iic_write( 0x1D, 1, buf );
    iic_read( 0x1D, 1, buf );
    alt_printf( "DEVID %x\n", buf[0] );

    /* Event loop never exits. */
    while( 1 ) {
        ;
    }

    return 0;
}
Example #8
0
static u8 gsl_write_interface(u8 reg,u8 *buf,u16 num)
{
    iic_write(reg,buf,num);
    return 1;
}