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

cross mob

CAPSENSE™ CY8CMBR3xxx: Calculating CRC and writing configuration data into non-volatile memory - KBA238362

CAPSENSE™ CY8CMBR3xxx: Calculating CRC and writing configuration data into non-volatile memory - KBA238362

Infineon_Team
Employee
Employee
50 replies posted 25 likes received 25 replies posted

Question: How do I calculate the CRC of 126 bytes of configuration data (using the CY8CMBR3xxx controller and host APIs) and write 128 bytes of data into non-volatile memory?

Note:  In 128 bytes, 126 bytes are configuration data, and the last two bytes are the CRC value.

Answer:

As per the CAPSENSE™ Express Controllers Registers TRM, the configuration registers (0x00-0x7E) contain the configuration data for the CY8CMBR3xxx controllers. A host can write into these registers and save the data to non-volatile memory by writing to the CTRL_CMD command register. The new configuration takes effect only when the configuration is saved to non-volatile memory and the device is reset.

For more details on I2C commands and their explanations, see “Advance Topics” from the CY3280-MBR3 Evaluation Kit User Guide.

To write the configuration data, follow the steps:

Note: Host APIs are used for CRC calculation.

  1. Consider the example of the SENSOR_EN register with the register address (0x00). For more details, see the “SENSOR_EN” section in the registers reference manual [1].
Infineon_Team_0-1696400395035.png

Figure 1  SENSOR_EN register

In the register, you can enable or disable capacitive sensor configuration.

  1. Write 0x01 to the SENSOR_EN register with the register address (0x00) (i.e., to enable sensor CS0 and to save the configuration in non-volatile memory such that the configuration will be retained even after reset).
  2. Execute the command w 37 00 01 p (see Figure 2) to write 0x01 to the SENSOR_EN register with the register address (0x00).
    Note:  Send multiple commands to avoid NACKs.
Infineon_Team_1-1696400464000.pngFigure 2  Bridge Control Panel command to write 0x01 to the SENSOR_EN register

  1. Read the first 126 bytes of configuration data from the register map using the below command:

r 37 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x p

 

Infineon_Team_2-1696400521676.png

Figure 3   Bridge Control Panel command to read first 126 bytes of configuration data

  1. Copy the 126-byte data and paste it in a text editor software (for example, Notepad) as shown below:
Infineon_Team_3-1696400564423.png

 

Figure 4 MBR configuration data copied from BCP to notepad

  1. Replace “+” (i.e., a plus sign and then one empty space) with “, 0x” (i.e., a comma, one empty space, 0 and x) as shown below:
Infineon_Team_4-1696400587959.png

Figure 5   Formatted MBR configuration data

  1. Create a C project and include the CY8CMBR3xxx_APIs.h and CY8CMBR3xxx_CRC.c files. Download the host APIs from Infineon-CY8CMBR3xxx_Host_APIs-ApplicationNotes-v09_00-EN.zip.
  2. Create a file main.c and enter the following code in it:

    Note:  Copy the formatted data to the “CY8CMBR3xxx_configuration[126]” array.

#include <stdio.h>

/* Variable to store 126 bytes of configuration data */

unsigned char CY8CMBR3xxx_configuration[126]= {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x05, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x58, 0x00, 0x37, 0x06, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

/* The main() function invokes the CY8CMBR3xxx_CalculateCrc API to compute the CRC for 126 bytes of configuration data */

int main(void)

{

/* Variable to store the 16-bit CRC value*/

unsigned short crcValue;

 

/* Call the "CY8CMBR3xxx_CalculateCrc" API with configuration data address as the argument*/

crcValue = CY8CMBR3xxx_CalculateCrc(CY8CMBR3xxx_configuration);

/* Print the calculated 16-bit CRC value*/

printf("The CRC for the given configuration data is: 0x%x",crcValue);

return 0;

} 

 

  1. Save and build the project.
    Make sure that there are no errors.
  2. After running the project, get the CRC value.
    The CRC value obtained is 1F FF.
Infineon_Team_5-1696400688038.png

Figure 6  CRC value

  1. Write the calculated CRC value to the CONFIG_CRC register. For more details, see the “CONFIG_CRC” section in the registers reference manual [1].
Infineon_Team_6-1696400735433.png

 

Figure 7  CONFIG_CRC register

  1. Execute the command w 37 7e FF 1F p (see Figure 8).
Infineon_Team_7-1696400769129.png

 

Figure 8   Bridge Control Panel command to write computed CRC into CONFIG_CRC register

  1. Write 0x02 to the CTRL_CMD regsiter to save the configuration data to non-volatile memory. For more details, see the “CTRL_CMD” section in the registers reference manual [1].
Infineon_Team_8-1696400785981.png

Figure 9 CTRL_CMD register

When you write 0x02 to the CTRL_CMD register, the device calculates the CRC checksum over the configuration data in this register map and compares the result with the content of CONFIG_CRC. If the two values match, the device saves the configuration and the CRC checksum to non-volatile memory.

A delay is inserted to wait until the command w 37 86 02 p [DELAY=220]is processed.

Infineon_Team_9-1696400818713.png

Figure 10  Saving the configuration data to non-volatile memory

  1. Read the CTRL_CMD_STATUS register to check if the configuration was saved successfully. For more details, see the “CTRL_CMD_STATUS” section in the registers reference manual [1].
Infineon_Team_10-1696400886762.png

 

Figure 11  CTRL_CMD_STATUS register

In this register, 1 to 7 bits are reserved. If the ERR bit is 0, that means no error has occurred and the configuration has been saved successfully. If the ERR bit is 1, it means an error has occurred.

  1. Execute the command w 37 88 r 37 x p (see Figure 12).
Infineon_Team_11-1696400911984.png

Figure 12  Checking CTRL_CMD_STATUS register

  1. Reset the device.
  2. Confirm if the value stored in the SENSOR_EN register with the register address (0x00) is 0x01.
  3. Execute the command w 37 00 r 37 x p.
Infineon_Team_12-1696400952416.png

 

Figure 13   Value stored in SENSOR_EN with the register address (0x00) is 0x01

Writing 0x01 to the SENSOR_EN register makes the 0th bit of the register equal to 1. This enables the CS0 sensor, which is the proximity sensor in the CY3280-MBR3 Kit. For more details, see the “SENSOR_EN” section in the registers reference manual [1].

Infineon_Team_13-1696400984304.png

 

Figure 14  CS0 sensor enables proximity sensor

Infineon_Team_15-1696401028941.pngFigure 15  Proximity sensor pin (for more information, see Datasheet)

  1. Check the proximity sensor for confirmation.
Infineon_Team_16-1696401082610.png

Figure 16 Proximity sensor enabled (top view)

Infineon_Team_17-1696401115692.png

Figure 17  Proximity sensor enabled (side view)

CRC can be calculated using the CY8CMBR3xxx controller as well. Instead of the earlier steps from #4 to #10, follow the steps below:

  1. Send the command w 37 86 03 p to compute the CRC of the 126 bytes of configuration data.
Infineon_Team_18-1696401156797.png

Figure 18   Bridge Control Panel command to compute CRC

Infineon_Team_19-1696401193016.png

 

Figure 19  CTRL_CMD register

For more details, see the “CTRL_CMD” section in the registers reference manual [1].

When you write 0x03 to the CTRL_CMD register, the device calculates a CRC checksum over the configuration data in this register map and places the result in the CALC_CRC register.

  1. Execute the command w 37 94 r 37 x x p to read the CRC value calculated by the MBR controller.

 

Infineon_Team_20-1696401217128.png

Figure 20  Bridge Control Panel command to read computed CRC value

Infineon_Team_21-1696401249149.png

Figure 21 Register CALC_CRC

For more details, see the “CALC_CRC” section in the registers reference manual [1].

This register stores the configuration data CRC that the host command opcode 0x03 calculated (see CTRL_CMD.CMD_OP_CODE).

After receiving the CRC value, follow steps from #11 to #19.

0 Likes
134 Views
Contributors