- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I'm still new to PSoC (and PSoC Creator) world: I would like to port some libraries that I wrote for STM32 MCU to PSoC, but I have some doubts about it.
The libraries that I wrote are intended to be used with MEMS sensors (temperature, pressure, and humidity) which communicate with the MCU over I2C. When I wrote them for STM32 MCU, I wanted them to be independent of the I2C interface chosen (I2C1, I2C2, I2C3,..), so that the programmer could choose which I2C to be used. Therefore, my code looked like this:
// Function prototype - I2C_TypeDef pointer
void readTemperature(I2C_TypeDef *I2C, SensorStruct sensor);
int main(void)
{
SensorStruct mySensor;
I2C_Init(I2C1);
while(1)
{
read_temperature(I2C1,&mySensor);
// Do some stuff
}
}
In PSoC, can I do something similar? My problem right now is that, if I write a library, I'll need to use some I2C methods, but these methods have to be called with the name of the component. So if I change the name of the component, I need to change it everywhere in my code, as follows:
// Programmer used I2C component naming it I2C
I2C_MasterSendStart(SLAVE_ADDRESS, READ);
// Programmer used I2C component naming it I2C_1
I2C_1_MasterSendStart(SLAVE_ADDRESS, READ);
What kind of approach do you suggest me?
Thank you in advance,
Davide
Solved! Go to Solution.
- Labels:
-
PSoC 5 Device Programming
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Davide,
One way to do it with PSoC is to encapsulate your library into a custom component. Inside the component you can have a schematic with stock I2C, named e.g. I2C_1 and API (library code). Then inside component API code you can refer to this I2C unique name like this: `$INSTANCE_NAME`_I2C_1. Whenever the component name is changed, the I2C name will update automatically.
For component creation look into
http://www.cypress.com/documentation/component-datasheets/psoc-creator-component-author-guide
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Davide,
One way to do it with PSoC is to encapsulate your library into a custom component. Inside the component you can have a schematic with stock I2C, named e.g. I2C_1 and API (library code). Then inside component API code you can refer to this I2C unique name like this: `$INSTANCE_NAME`_I2C_1. Whenever the component name is changed, the I2C name will update automatically.
For component creation look into
http://www.cypress.com/documentation/component-datasheets/psoc-creator-component-author-guide
/odissey1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi odissey,
thank you for your reply. I'm trying to build a custom component integrating a stock I2C in the component schematic, but my doubt is that, doing this, the stock I2C of the custom component cannot be used for other purposes: is it right?
Thanks,
Davide
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Davide,
Yes this is the case. Once a component is Incorporated it is no longer useful for other tasks (AFAIK).
/odissey1