PSoC™ 4 Forum Discussions
Some how all the PSOC5 code written for I2CMaster component in POSC5 fails when ported over to PSOC4
This is a snippet for Inter Processor communication using I2C( I2C Master on PSOC5 and EzI2C on PSOC4 slave) in a multi-processor system that I have written. And it works.
Now When I tried to port this code which was written for PSOC5 to another system using PSOC4() and another controller, I saw that it breaks. I had to bit-bag for it to work.
In fact, the code examples from Cypress Website also can not send any data on the bus as I tried to monitor using a beagle I2C sniffer. Any idea? I can configure my SCL and SDA as Open Drain pins in PSOC5. in PSOC4 I have no option of creating GPIO pins first and then wiring/connecting the I2CMaster block on to them.
///////////////////////////////////////////////////
// Reading data from Monitor CPU
//////////////////////////////////////////////////
uint8 MonitorCPUI2CReadByte(uint8 read_cmd)
{
uint8 i2c_status=FALSE;
uint8 return_data = 0;
//uint8 i;
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterWriteByte(read_cmd); // EXT EEPROM command
if(i2c_status == I2C_Master_MSTR_NO_ERROR)
{
i2c_status = I2C_Master_MasterSendRestart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_READ_XFER_MODE);
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
return_data = I2C_Master_MasterReadByte(I2C_Master_NAK_DATA); // MSB data
}
else
{
GUI_DispStringAt ("ERR1_I2C_MONITOR_CPU_RX", 100,70);
}
}
else
{
GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_RX", 100,10);
}
}
else
{
GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_RX", 100,50);
}
I2C_Master_MasterSendStop(); // Send Stop
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
}
else
{
GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_RX", 100,70);
}
if(I2C_Master_MSTR_NO_ERROR != i2c_status )
{
return_data = FALSE;
}
CyDelay(EEPROM_OP_DELAY_MS);
ServiceWatchDogAndCheckHeartBeat();
return(return_data);
}
///////////////////////////////////////////////////
// Sending a command to Monitor CPU
//////////////////////////////////////////////////
uint8 MonitorCPUI2CWriteByte(uint8 write_addr, uint8 write_data)
{
uint8 i2c_status=FALSE;
uint8 status =FALSE;
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterWriteByte(write_addr); // EXT EEPROM command
if(I2C_Master_MSTR_NO_ERROR == status)
{
status = I2C_Master_MasterWriteByte(write_data); // EXT EEPROM command
if(status == I2C_Master_MSTR_NO_ERROR)
{
status =TRUE;
}
else
{
GUI_DispStringAt ("ERR1_I2C_MONITOR_CPU_WR", 100,10);
}
}
else
{
GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_WR", 100,10);
}
}
else
{
GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_WR", 100,50);
}
I2C_Master_MasterSendStop(); // Send Stop
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
}
else
{
GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_WR", 100,70);
}
if(I2C_Master_MSTR_NO_ERROR != i2c_status )
{
status = FALSE;
}
CyDelay(EEPROM_OP_DELAY_MS);
ServiceWatchDogAndCheckHeartBeat();
return(status);
}
///////////////////////////////////////////////////
// Reading data from Monitor CPU
//////////////////////////////////////////////////
uint8 MonitorCPUI2CBlockRead(uint8 read_cmd, uint8* read_data, uint8* data_len)
{
uint8 i2c_status=FALSE;
uint8 status=FALSE;
uint8 i=0;
//uint8 read_buff[CPU2_BLK_READ_SIZE]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
if(NULL != data_len)
{
//uint8 i;
if(*data_len < CPU2_BLK_READ_SIZE)
{
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterWriteByte(read_cmd); // EXT EEPROM command
if(i2c_status == I2C_Master_MSTR_NO_ERROR)
{
i2c_status = I2C_Master_MasterSendRestart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_READ_XFER_MODE);
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
for(i=0;i<(*data_len);i++)
{
if(i<((*data_len)-1))
{
read_data=I2C_Master_MasterReadByte(I2C_Master_ACK_DATA);
}
else
{
read_data=I2C_Master_MasterReadByte(I2C_Master_NAK_DATA);
}
ServiceWatchDogAndCheckHeartBeat();
}
}
else
{
GUI_DispStringAt ("ERR1_I2C_MONITOR_CPU_RD", 100,70);
}
}
else
{
GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_RD", 100,10);
}
}
else
{
GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_RD", 100,50);
}
I2C_Master_MasterSendStop(); // Send Stop
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
}
else
{
GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_RD", 100,70);
}
if(I2C_Master_MSTR_NO_ERROR != i2c_status )
{
status = FALSE;
(*data_len) =0;
}
}
else
{
(*data_len) =0;
}
CyDelay(EEPROM_OP_DELAY_MS);
}
ServiceWatchDogAndCheckHeartBeat();
return(status);
}
///////////////////////////////////////////////////
// Sending a block of data to Monitor CPU
//////////////////////////////////////////////////
uint8 MonitorCPUI2CBlockWrite(uint8 write_addr, uint8 *write_data, uint8 data_len)
{
uint8 i2c_status=FALSE;
uint8 status =FALSE;
uint8 i;
if((NULL != write_data) && (data_len <CPU2_BLK_WRITE_SIZE))
{
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
i2c_status = I2C_Master_MasterWriteByte(write_addr); // EXT EEPROM command
if(I2C_Master_MSTR_NO_ERROR == i2c_status)
{
for(i=0;((i<data_len)&&(I2C_Master_MSTR_NO_ERROR == i2c_status ));i++)
{
i2c_status = I2C_Master_MasterWriteByte(write_data); // device address
ServiceWatchDogAndCheckHeartBeat();
}
if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors
{
status=TRUE;
}
else
{
GUI_DispStringAt ("ERR1_I2C_ERTC_WR", 100,50);
}
}
else
{
GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_WR", 100,10);
}
}
else
{
GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_WR", 100,50);
}
I2C_Master_MasterSendStop(); // Send Stop
i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */
}
else
{
GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_WR", 100,70);
}
if(I2C_Master_MSTR_NO_ERROR != i2c_status )
{
status = FALSE;
}
CyDelay(EEPROM_OP_DELAY_MS);
}
ServiceWatchDogAndCheckHeartBeat();
return(status);
}
///////////////////////////////////////////////////// Reading data from Safety CPU//////////////////////////////////////////////////uint8 MonitorCPUI2CReadByte(uint8 read_cmd) { uint8 i2c_status=FALSE; uint8 return_data = 0; //uint8 i; i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterWriteByte(read_cmd); // EXT EEPROM command if(i2c_status == I2C_Master_MSTR_NO_ERROR) { i2c_status = I2C_Master_MasterSendRestart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_READ_XFER_MODE); if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { return_data = I2C_Master_MasterReadByte(I2C_Master_NAK_DATA); // MSB data } else { GUI_DispStringAt ("ERR1_I2C_MONITOR_CPU_RX", 100,70); } } else { GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_RX", 100,10); } } else { GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_RX", 100,50); } I2C_Master_MasterSendStop(); // Send Stop i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ } else { GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_RX", 100,70); } if(I2C_Master_MSTR_NO_ERROR != i2c_status ) { return_data = FALSE; } CyDelay(EEPROM_OP_DELAY_MS); ServiceWatchDogAndCheckHeartBeat(); return(return_data); }
///////////////////////////////////////////////////// Sending a command to Safety CPU//////////////////////////////////////////////////uint8 MonitorCPUI2CWriteByte(uint8 write_addr, uint8 write_data) { uint8 i2c_status=FALSE; uint8 status =FALSE; i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterWriteByte(write_addr); // EXT EEPROM command if(I2C_Master_MSTR_NO_ERROR == status) { status = I2C_Master_MasterWriteByte(write_data); // EXT EEPROM command if(status == I2C_Master_MSTR_NO_ERROR) { status =TRUE; } else { GUI_DispStringAt ("ERR1_I2C_MONITOR_CPU_WR", 100,10); } } else { GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_WR", 100,10); } } else { GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_WR", 100,50); } I2C_Master_MasterSendStop(); // Send Stop i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ } else { GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_WR", 100,70); } if(I2C_Master_MSTR_NO_ERROR != i2c_status ) { status = FALSE; } CyDelay(EEPROM_OP_DELAY_MS); ServiceWatchDogAndCheckHeartBeat(); return(status); }
///////////////////////////////////////////////////// Reading data from Safety CPU//////////////////////////////////////////////////uint8 MonitorCPUI2CBlockRead(uint8 read_cmd, uint8* read_data, uint8* data_len) { uint8 i2c_status=FALSE; uint8 status=FALSE; uint8 i=0; //uint8 read_buff[CPU2_BLK_READ_SIZE]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; if(NULL != data_len) { //uint8 i; if(*data_len < CPU2_BLK_READ_SIZE) { i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterWriteByte(read_cmd); // EXT EEPROM command if(i2c_status == I2C_Master_MSTR_NO_ERROR) { i2c_status = I2C_Master_MasterSendRestart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_READ_XFER_MODE); if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { for(i=0;i<(*data_len);i++) { if(i<((*data_len)-1)) { read_data=I2C_Master_MasterReadByte(I2C_Master_ACK_DATA); } else { read_data=I2C_Master_MasterReadByte(I2C_Master_NAK_DATA); } ServiceWatchDogAndCheckHeartBeat(); } } else { GUI_DispStringAt ("ERR1_I2C_MONITOR_CPU_RD", 100,70); } } else { GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_RD", 100,10); } } else { GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_RD", 100,50); } I2C_Master_MasterSendStop(); // Send Stop i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ } else { GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_RD", 100,70); } if(I2C_Master_MSTR_NO_ERROR != i2c_status ) { status = FALSE; (*data_len) =0; } } else { (*data_len) =0; } CyDelay(EEPROM_OP_DELAY_MS); } ServiceWatchDogAndCheckHeartBeat(); return(status); }///////////////////////////////////////////////////// Sending a block of data to Safety CPU//////////////////////////////////////////////////uint8 MonitorCPUI2CBlockWrite(uint8 write_addr, uint8 *write_data, uint8 data_len) { uint8 i2c_status=FALSE; uint8 status =FALSE; uint8 i; if((NULL != write_data) && (data_len <CPU2_BLK_WRITE_SIZE)) { i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ if(I2C_Master_MSTR_NO_ERROR == i2c_status ) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterSendStart(I2C_SLAVE_ADDR_SAFETY_CPU, I2C_Master_WRITE_XFER_MODE); // device address if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { i2c_status = I2C_Master_MasterWriteByte(write_addr); // EXT EEPROM command if(I2C_Master_MSTR_NO_ERROR == i2c_status) { for(i=0;((i<data_len)&&(I2C_Master_MSTR_NO_ERROR == i2c_status ));i++) { i2c_status = I2C_Master_MasterWriteByte(write_data); // device address ServiceWatchDogAndCheckHeartBeat(); } if(I2C_Master_MSTR_NO_ERROR == i2c_status) // Check if transfer completed without errors { status=TRUE; } else { GUI_DispStringAt ("ERR1_I2C_ERTC_WR", 100,50); } } else { GUI_DispStringAt ("ERR2_I2C_MONITOR_CPU_WR", 100,10); } } else { GUI_DispStringAt ("ERR3_I2C_MONITOR_CPU_WR", 100,50); } I2C_Master_MasterSendStop(); // Send Stop i2c_status = I2C_Master_MasterClearStatus(); /* Clear any previous status */ } else { GUI_DispStringAt ("ERR4_I2C_MONITOR_CPU_WR", 100,70); } if(I2C_Master_MSTR_NO_ERROR != i2c_status ) { status = FALSE; } CyDelay(EEPROM_OP_DELAY_MS); } ServiceWatchDogAndCheckHeartBeat(); return(status); }
I want to change device security from code. I want to change from OPEN to PROTECTED.
Reading TRM the register CPUSS_PROTECTION must be written to.
But when i try to access this register I end up in the interrupt default handler.
What i tried to do:
uint32 CpuSsProtection = CY_GET_XTND_REG32( (void CYFAR *)(CYREG_CPUSS_PROTECTION) );
if ( (CpuSsProtection & 0x0000000F) < (uint32_t)0x02 )
{
CpuSsProtection = (uint32_t)0x02; // Set CPUSS_PROT to PROTECTED mode - note this disables debug and flash read operations
CY_SET_XTND_REG32( (void CYFAR *)(CYREG_CPUSS_PROTECTION), CpuSsProtection );
// Reset to run with this setup
//CySoftwareReset();
}
But as stated, just trying to read the register crashes the PSOC.
So how is the correct way to go about this.
Note that this must be done in code and not through the PSOC Creator IDE.
Show LessI use CY8C4248LQI-BL583 to design a 4 channels ADC application. I also use BLE to transfer acquired data out. It works fine when I set "Vref selection" in ADC at VDDA and VDDA/2. But BLE can't work when I set "Vref selection" in ADC at Internal 1.024 volts (or others). Anyone know why? And how can I solve this problem?
Show LessHello,
I am trying to send data from one PSoC to another PSoC through BLE.
I am following the examples from PSoC 4 100 projects in 100 days.
But I am using custom profile, unlike the Device Information Service in example.
Currently the two devices get connected but am not able to read data on that custom characteristic handle.
Thanks,
Ameya
Show LessHello, I'm working on an application which includes CAN/SPI/CAPSENSE. What I'm trying to make sure is that would any of these functions go wrong if there are no ECO(XTAL) sync'd with PSOC 4100. I'm pretty getting close to the point that CAPSENSE/SPI would work fine in XTAL-less environment. What nags me now is CAN.
1. Did anyone experience flaws in CAN without XTAL even in high/low temp situations?
and one more thing.
2. Datasheet very roughly advises me that any XTAL freq ranging from 4~32MHz would be OKAY for PSOC 4100. Does that mean it would work with fractional frequencies(i.e 27.12MHz)?
regards,
Show LessHello,
I've designed a circuit for the CYBLE 224116-01 chip. My concern is the connections i have from the 10 pin header. From what i know there needs to be a connection to the VDD pin. However, as a result of the design through one connection to the power supply ferrite bead, the header is connected to the VDDA and VDDR pin as well.
Will this majorly have an affect on the programming of the chip ?
Regards,
Alisha Khan
Show LessI have ran thru the source code for CySmart iOS and Android and began the bootloader implementation for adding OTA to my existing apps although this seems way more cumbersome than I would assume. I can upgrade my PSOC device using the CySmart mobile apps fine after adding all required bootloader steps to our projects but the mobile app side hasn't been added yet. Am I missing something with the usage here? Has anyone created a drop in class(s) I can add to my project, feed it a file and let it execute a simple OTA upgrade process with checksum, etc? The CySmart app is full of callbacks and trying to rip that apart to implement into our projects is causing a lot more work than I assumed would be needed.
For instance, the WICED supported Broadcom setup is as close to a drop in as I would expect and would be awesome if supported with the PSOC 4.
Show LessHi,
When the ProC4 is flashed, is the flash image CRC stored anywhere in flash/sflash etc. by default?
I have the programming specification for this which shows it is in the hex file and how to calculate if programming, but I'm not seeing that it's stored on the device anywhere at programming. Is this correct?
I guess I could add the checksum to sflash or similar, but if it's readable somewhere, that would be great.
Thanks, Dave
Show Lesswww.cypress.com/file/135786/download
and that downloads CY8CKIT04942xxSetupOnlyPackage_revSA.exe
When I tried to open that up by double clicking it I got missing file
windows\system32\advpack.dll (but found it on computer already)
After I downloaded a couple of programs that was suppose to fix the error massage found both programs did not work.
why is it so hard to unpack the the file, I take it all the file is that it is a self unpacking program
Show Less