Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
Question: How do I change the address of I2CHW slave dynamically?
By default, in I2CHW Slave user module, the address is configured as a user module parameter and hence cannot be changed dynamically in the project.By making some custom modifications to the I2CHW source file, dynamic addressing may be implemented.
1. Open the I2CHW_1Int.asm file from the "lib\Library Source Files" folder in the Workspace Explorer.
2. Add the following code inside the custom code area marker beginning with @PSoC_UserCode_INIT@ (Do not change this line.)
This will create a variable "SlaveAddress" to hold the dynamic slave address. The "_" before the variable is to access the variable from C.
3. Find the Label "NewADDRNotSet:"
4. Below this label there is a custom code area marker "@PSoC_UserCode_BODY4@"
5. Inside this area, comment out the following code, which does an address compare with the value set in the I2CHW user module parameter.
6. Add the following code, which now compares the address with the value stored in variable SlaveAddress
xor A, [_SlaveAddress]
7. In your C source file, add a reference to the SlaveAddress variable
extern BYTE SlaveAddress;
8. Update the variable SlaveAddress with the desired Slave Address.For example