Home>

I want to implement S-35390A (real-time clock) using MCC with PIC

Data cannot be read by I2C.

Corresponding source code
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/examples/i2c_master_example.h"
uint8_t g_i2c [20];
/ *
    Main application
* /
void main (void)
{
    // initialize the device
    SYSTEM_Initialize ();
    // When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
    // Use the following macros to:
    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable ();
    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable ();
    // Disable the Global Interrupts
    // INTERRUPT_GlobalInterruptDisable ();
    // Disable the Peripheral Interrupts
    // INTERRUPT_PeripheralInterruptDisable ();
    I2C_ReadNBytes (0x60,&g_i2c [0], 1);
    // After this, g_i2c [0] contains only 0
    while (1)
    {
        // Add your application code
    }
}
What I tried

MCC settings
Interrupt Driven: ON
Serial Protocol: I2C
Mode: Master
I2C Clock Frequency (Hz): 100000
Enable I2C Interrupt: ON

The pin settings are not changed by default.
Wiring is not a problem as it worked with the CCS compiler.

Supplementary information

Includes "i2c_master_example.h" automatically generated by MCC.
When I check the data sheet, it says, "Do not input an acknowledgment signal (NO_ACK) to the last data byte from the master device." Is it possible to set such a thing in MCC?

Referenced site

pic
  • Answer # 1

    Isn't i2c address specified by 7 bits?

    // I2C_ReadNBytes (0x60,&g_i2c [0], 1);
    I2C_ReadNBytes (0x30,&g_i2c [0], 1);


    Reference
    Control LED lighting with a PIC microcomputer (14)

    // Slave address setting
    #define dfPCA9635_SLVADDR 0x40 // I2C slave write address [7bit]-(7bit + Write) 0x80/​​(7bit + Read) 0x81

  • Answer # 2

    I haven't used MCC very much, so I don't know what kind of code will be generated, but

    When the master receives, returning ACK has the meaning of "please give me another byte".
    What I want to say is that NACK (= "I don't need it anymore") at the end is a standard I2C operation.
    So I guess it's already happening.

    // After this, g_i2c [0] contains only 0

    Why read only 1 byte?
    That address (status register 1) can be 0 during normal operation.
    * Since it says "It worked with CCS compiler", POC may have already been cleared.
    You should read 1 "after surely powering down" by removing the battery.

    In any case, I don't know what kind of RTC I tried this code with.
    (You can tell if you are)
    Maybe it's working (reading) properly.

    Why don't you read and write a little more?