Обращаюсь к MAX6956 из Kinetic K70.
Насчет чтения в документации написано так
Цитата
The MAX6956 is read using the MAX6956’s internally stored command byte as address pointer, the same way the stored command byte is used as address pointer for a write. The pointer generally autoincrements after each data byte is read using the same rules as for a write (Table 4). Thus, a read is initiated by first configuring the MAX6956’s command byte by performing a write (Figure 8). The master can now read n consecutive bytes from the MAX6956, with the first data byte being read from the register addressed by the initialized command byte. When performing read-afterwrite verification, remember to reset the command byte’s address because the stored control byte address generally has been autoincremented after the write.
Чтение
Код
#define MAX6956_SLAVE_ADDR 0x80 //A0,A1-GND
void MAX6956_Read(unsigned char reg_addr, unsigned char *reg_data)
{
unsigned char slave_addr = MAX6956_SLAVE_ADDR | 0x01;
//--------------first - set the address to read from
//Start
I2C1_Start()
/* Send Slave Address with W/R bit = 1 */
I2C1_write_byte(slave_addr);
I2C1_Wait();
/* Write Register Address */
I2C1_write_byte(reg_addr);
I2C1_Wait();
//-------------second - read from the address
/* Do a repeated start */
I2C1_RepeatedStart(); //???
/* Send Slave Address */
I2C1_write_byte(slave_addr);
I2C1_Wait();
/* Write Register Address */
I2C1_write_byte(reg_addr);
I2C1_Wait();
/* Put in Rx Mode */
//I2C1_C1 &= (~I2C_C1_TX_MASK);
/* Turn off ACK since this is second to last byte being read*/
//I2C1_C1 |= I2C_C1_TXAK_MASK;
/* read */
*reg_data = I2C1_D;
I2C1_Wait();
/* Send stop since about to read last byte */
I2C1_Stop();
}
void MAX6956_Read(unsigned char reg_addr, unsigned char *reg_data)
{
unsigned char slave_addr = MAX6956_SLAVE_ADDR | 0x01;
//--------------first - set the address to read from
//Start
I2C1_Start()
/* Send Slave Address with W/R bit = 1 */
I2C1_write_byte(slave_addr);
I2C1_Wait();
/* Write Register Address */
I2C1_write_byte(reg_addr);
I2C1_Wait();
//-------------second - read from the address
/* Do a repeated start */
I2C1_RepeatedStart(); //???
/* Send Slave Address */
I2C1_write_byte(slave_addr);
I2C1_Wait();
/* Write Register Address */
I2C1_write_byte(reg_addr);
I2C1_Wait();
/* Put in Rx Mode */
//I2C1_C1 &= (~I2C_C1_TX_MASK);
/* Turn off ACK since this is second to last byte being read*/
//I2C1_C1 |= I2C_C1_TXAK_MASK;
/* read */
*reg_data = I2C1_D;
I2C1_Wait();
/* Send stop since about to read last byte */
I2C1_Stop();
}
Для проверки обращаюсь в регистр с известным значением после рисета.
Код
MAX6956_Read( 0x09, &data);
if (data != 0xAA)
return MAX6956_ERROR;
if (data != 0xAA)
return MAX6956_ERROR;
На скопе вижу клок на SCL (400 kHz), вижу правильные адреса на SDA а возвращаемое значение 0х81.