I2C not working on M0 on PSoC 62S2 Wi-Fi BT Pioneer Board

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
chwaitang
Level 3
Level 3
First solution authored 25 sign-ins 10 replies posted

Hi All,

I have try to port the I2C program for I2C which is proven working on M4 CPU over to M0 CPU to reserve M4 for wireless connectivity tasks.

I have found the same I2C program is not working on M0 core (Peripheral device initialisation on M0 core has no problem) but is working on M4 core. PDL library is used in both.

I have observe the I2C electrical waveform on scope and found the only difference between M0 and M4 is there is no further I2C transmissions after very first byte of the I2C device address on M0. I test out the I2C communication using an I2C EEPROM 24lc128. The electrical waveform shows /ACK from EEPROM but there is no more communication after that. 

 

Single step debug always show same problem of timeout after the very 1st byte which cause I2C communication to break down. I have attached archive file with 2 separate folders named CM0 and CM4 for your reference, similar generated source files for both are also attached as the device configuration between older working I2C on M4 and non working I2C on M0 are different. Attachment is 38MB.

Please advise.

 

Share Link https://1drv.ms/u/s!AqUm9KKUVNnphe5Zffg40tcflj05zg?e=GdmpjN

 

Thank and Best regards

CW

 

 

 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

I found a few issues in the fimware you shared for the CM0+ core, and mainly you have not configured the system and the clocks necessary for the peripherals.

To make things easier while developing for the CM0+ core, I have made a sample firmware for the CM0+ firmware which configures and initializes both I2C and UART. I tested this firmware and was successful in reading the date and time from an RTC module I had with me via I2C.
I have attached this firmware here and you can directly try and build this firmware and modify the firmware with your EEPROM address and pins to check if the EEPROM read and writes are successful via I2C.

Few considerations to be observed before going ahead with the build of the attached project:

1. Please modify the flash size to 0x8000 in the  linker script for the CM0+ core in the following path :
<project directory>\libs\TARGET_CY8CKIT-062-WIFI-BT\COMPONENT_CM0P\TOOLCHAIN_GCC_ARM\cy8c6xx7_cm0plus.ld

After modification it should be as follows:
flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x8000

2. Since you may not have the RTC module to connect to pins P6[0] and P6[1] I2c lines of the Wifi-BT board, you will observe the error 'CY_SCB_I2C_MASTER_ADDR_NAK' in the UART serial terminal every time the function rtc_getSeconds() is called in the main super-loop. Please modify the i2c read and write API's as needed for your EEPROM module here.

3. The design.modus file present in the project directory will create a Generated_Sources folder for you. Because of this, instead of creating the PDL configuration structures for the peripherals manually as you have done for the CM0+ firmware, I have used this device configurator to generate the config structures for me in this Generated_Sources folder. Once this is done, all the system clocks, peripherals and pins can be easily initialized by calling the following API's in the firmware

 

    init_cycfg_system();
    init_cycfg_clocks();
    init_cycfg_routing();
    init_cycfg_peripherals();
    init_cycfg_pins();

 

Also make sure to include the following header files in the routine the above API's are called:

 

#include "cy_pdl.h"
#include "cycfg_pins.h"
#include "cycfg_clocks.h"
#include "cycfg_routing.h"
#include "cycfg_peripherals.h"

 

NOTE: The design.modus and Generated_Sources folder in the path "<project directory>\libs\TARGET_CY8CKIT-062-WIFI-BT\COMPONENT_BSP_DESIGN_MODUS" will not be considered for the CM0+ firmware.

4. Simply launch the device configurator from the quick panel of ModusToolbox or double click on the design.modus file in the path <project director>/design.modus to modify the I2C pins for your EEPROM device.

This method of using the device configurator will help you to easily configure the peripherals for the CM0+ core.
Please do let me know if you have any difficulties or errors when trying out this approach.

Warm Regards
Alen

View solution in original post

0 Likes
11 Replies
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

Thank you for using our products.
I will check on this issue and revert back to you for the same at the earliest.

Warm Regards
Alen

0 Likes
lock attach
Attachments are accessible only for community members.
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

I found a few issues in the fimware you shared for the CM0+ core, and mainly you have not configured the system and the clocks necessary for the peripherals.

To make things easier while developing for the CM0+ core, I have made a sample firmware for the CM0+ firmware which configures and initializes both I2C and UART. I tested this firmware and was successful in reading the date and time from an RTC module I had with me via I2C.
I have attached this firmware here and you can directly try and build this firmware and modify the firmware with your EEPROM address and pins to check if the EEPROM read and writes are successful via I2C.

Few considerations to be observed before going ahead with the build of the attached project:

1. Please modify the flash size to 0x8000 in the  linker script for the CM0+ core in the following path :
<project directory>\libs\TARGET_CY8CKIT-062-WIFI-BT\COMPONENT_CM0P\TOOLCHAIN_GCC_ARM\cy8c6xx7_cm0plus.ld

After modification it should be as follows:
flash (rx) : ORIGIN = 0x10000000, LENGTH = 0x8000

2. Since you may not have the RTC module to connect to pins P6[0] and P6[1] I2c lines of the Wifi-BT board, you will observe the error 'CY_SCB_I2C_MASTER_ADDR_NAK' in the UART serial terminal every time the function rtc_getSeconds() is called in the main super-loop. Please modify the i2c read and write API's as needed for your EEPROM module here.

3. The design.modus file present in the project directory will create a Generated_Sources folder for you. Because of this, instead of creating the PDL configuration structures for the peripherals manually as you have done for the CM0+ firmware, I have used this device configurator to generate the config structures for me in this Generated_Sources folder. Once this is done, all the system clocks, peripherals and pins can be easily initialized by calling the following API's in the firmware

 

    init_cycfg_system();
    init_cycfg_clocks();
    init_cycfg_routing();
    init_cycfg_peripherals();
    init_cycfg_pins();

 

Also make sure to include the following header files in the routine the above API's are called:

 

#include "cy_pdl.h"
#include "cycfg_pins.h"
#include "cycfg_clocks.h"
#include "cycfg_routing.h"
#include "cycfg_peripherals.h"

 

NOTE: The design.modus and Generated_Sources folder in the path "<project directory>\libs\TARGET_CY8CKIT-062-WIFI-BT\COMPONENT_BSP_DESIGN_MODUS" will not be considered for the CM0+ firmware.

4. Simply launch the device configurator from the quick panel of ModusToolbox or double click on the design.modus file in the path <project director>/design.modus to modify the I2C pins for your EEPROM device.

This method of using the device configurator will help you to easily configure the peripherals for the CM0+ core.
Please do let me know if you have any difficulties or errors when trying out this approach.

Warm Regards
Alen

0 Likes
chwaitang
Level 3
Level 3
First solution authored 25 sign-ins 10 replies posted

Hi Alen,

Thanks for help!

Warm regards

CW

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

Glad your query is resolved.
Please feel free to post any queries or issues you may have on Infineon products in the community and we will be happy to help.

Warm Regards
Alen

0 Likes
chwaitang
Level 3
Level 3
First solution authored 25 sign-ins 10 replies posted

Hi Alen,

Sorry for early cheers

This query is still not resolved. I just shelved it to finish up wifi Matt data post using M4 first.

When I port the initialisation over to M0, the I2C problem described above still exists. Since it always timeout in the do-while loop after Cy_SCB_I2C_MasterWrite with ACK received from I2C device (see below), I believe have to dive deeper into PDL I2C driver to find the cause.

    error_code = Cy_SCB_I2C_MasterWrite(mI2C1_HW, &i2c1_transfer, &i2c1_Context1);

    if(error_code == CY_SCB_I2C_SUCCESS)

    {

        /* Wait until master complete read transfer or time out has occurred */

        do

        {

            masterStatus  = Cy_SCB_I2C_MasterGetStatus(mI2C1_HW, &i2c1_Context1);

            Cy_SysLib_DelayUs(CY_SCB_WAIT_1_UNIT);

            timeout--;

        } while ((0UL != (masterStatus & CY_SCB_I2C_MASTER_BUSY)) && (timeout > 0));

 

        if (timeout <= 0)

        {

            /* Timeout recovery */

        Cy_SCB_I2C_MasterSendStop(SCB1, 1, &i2c1_Context1);

        Cy_SCB_I2C_Disable(mI2C1_HW, &i2c1_Context1);

        CyDelay(1);

            Cy_SCB_I2C_Enable (mI2C1_HW);

            error_code = CY_SCB_I2C_MASTER_MANUAL_TIMEOUT;

        }

        else

        {

            if ((0u == (MASTER_ERROR_MASK & masterStatus)) && (i2c1_transfer.bufferSize == Cy_SCB_I2C_MasterGetTransferCount(mI2C1_HW, &i2c1_Context1)))

            error_code = CY_SCB_I2C_SUCCESS;

            else

            error_code = masterStatus;

        }

    }

 

I'll do this later. In meantime, do u know the solution?

Warm regards

CW

0 Likes
chwaitang
Level 3
Level 3
First solution authored 25 sign-ins 10 replies posted

In addition, after I port the initialisation to M0 and remove the ipc  semaphore, I find wifi code not running on M4.

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

Can you please let me know the value of error_code? (in Hex if possible) after the line   
 
error_code = Cy_SCB_I2C_MasterWrite(mI2C1_HW, &i2c1_transfer, &i2c1_Context1);


In the firmware I shared, in i2c_init() in i2c.c, I have registered a callback to see hardware errors

    //Register a even callback to get errors of addrass NAK
    Cy_SCB_I2C_RegisterEventCallback(I2C_SCB_HW,i2c_interrupt_eventsCallback,&cy_stc_scb_i2c_context);


This will help you debug more on if whether you have any hardware issues like address NAK or bus arbitration loss in the i2c lines given by the CY_SCB_I2C_MASTER_ERR_EVENT.
Can you let me know, by debugging, If the i2c_interrupt_eventsCallback is being called after the Cy_SCB_I2C_MasterWrite and if yes, what is the return value (in hex) of Cy_SCB_I2C_MasterGetStatus() inside the i2c_interrupt_eventsCallback() API.

Warm Regards
Alen

0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

I have modified M0 I2C code to test with an I2C EEPROM chip using i2c_test function and it works fine. But the actual code for working with icm20948 which was proven working on M4 is now not working on M0 (Just comment out the test_i2c() and uncomment ICM20948_Start().

In addition, when I uncomment ICM20948_Calibrate() to run, it always stuck within and hang, never exit from this function. These 3 lines of code from ICM20948_Start() to clearI2C_Buffer() has been verify working on M4 b4. It seems I have been seeing this kind of problems with codes ported from M4. I have check to ensure no Hal functions in them. Question: Does PSoC 6M0 support HAL now? So I can't seem to understand why they do not work.

Please advise.

Thanks and Regards

CW 

 

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

I saw the API ICM20948_whoAmI() inside the ICM20948_Start() routine. Can you please comment out the rest of the code and only run the whoAmI() to see if it returns failure or success?

>> I have modified M0 I2C code to test with an I2C EEPROM chip using i2c_test function and it works fine.
If your I2C is working here, then I believe this is an issue in the driver implementation you have done for the ICM20948. I would suggest you take one register of this motion sensor, say the whoAmI register, and try reading from it using I2C without using the driver code provided in icm20948.c but only using raw Cy_SCB_I2C_MasterWrite()  API's to see if the issue is with I2C or non responsiveness of the motion sensor.

Also, your initial query was on the I2C EEPROM operation, so is this working over CM0+ core as expected now?

 Question: Does PSoC 6M0 support HAL now? So I can't seem to understand why they do not work.
A] No, HAL API's are not supported in PSoC 6 CM0P core. If they are present in the same, then the compiler will throw an error during build.

Warm Regards
Alen

0 Likes

Hi Alen,

 

Thanks, I found the problem. It seems I am using a local

cy_stc_scb_i2c_context_t i2c1_Context in icm20948.c

Without previous init info, it default to IDLE state and never trigger I2C function. I replaced with common context variable for same hardware I2C peripheral using extern and  everything is good now.

Thanks!

CW

0 Likes
AlenAn14
Moderator
Moderator
Moderator
500 replies posted 100 solutions authored 250 replies posted

Hi @chwaitang ,

The context variable should be global instead of local as it keeps track of the I2C operations for the SCB block.
Glad you got this to work and thank you for sharing the resolution in the community.

Warm Regards
Alen

0 Likes