Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8374

SDK • i2c routine question.

$
0
0
Hi all,

I have a question regarding the i2c routines in the SDK, on my i2c bus I have : MCP23017 I/O expander, a 24xx serial EEPROM and a PCF2129AT realtime clock which is configured for i2c operation, bus is 400KHz, and pullups are 2K.

Reads and writes to the EEPROM and I/O expander are absolutely fine. But the PCF2129AT is misbehaving.

After a pico reset, I initialize the PCF2129AT by writing to some of it's configuration registers, to set things like no interrupt output or clock output, I then do a read to get the current time this works and returns the current time and date. However subsequent reads return corrupted values.

I note from the PCF2129AT data sheet that to do a read of the registers I should first do a write of I2c address, register number. And then do a read of i2c address, first byte, second byte...nthe byte. However it specifies that the last byte should not be acknowledged by the pico, does the i2c_read_blocking do this?

My code :

Code:

#define CMD_REG_MASK 0 /*  Read a set of registers from the RTC into a pointed to array.  NOTE: FirstReg is first reg to fetch from the RTC, it is *NOT* an index        into Regs, Regs[0]..Regs[Count] are received.*/void rtcGetRegs(uint8_t     FirstReg,                uint8_t     Count,                uint8_t     *Regs){    uint8_t CmdByte;    int result;    // Generate command, and combine with first register      CmdByte = CMD_READ | (FirstReg & CMD_REG_MASK);               // Send command byte to RTC    i2c_write_blocking(I2C_PORT,RTC_ADDRESS,&CmdByte,1,false);        // Receive register bytes to RTC    result=i2c_read_blocking(I2C_PORT,RTC_ADDRESS,&Regs[0],Count,false);#if (DEBUG_RTC == 1)    printf("rtcGetRegs result=%d, returns\n",result);    HexDumpHead(&Regs[0],Count);#endif}


Cheers.

Phill.

Statistics: Posted by PhillHS — Fri Jan 16, 2026 5:06 pm



Viewing all articles
Browse latest Browse all 8374

Trending Articles