- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey guys.
I've managed to set my ESP32 up as a master device and im trying to get a value from a sensor that is connected to my PSOC, so my psoc is my slave. When I load the code to each device, the first few iterations will indeed send the values im reading from the PSOC to the ESP, but from there on I get no values back from the request function of my master and it stops sending information.
I've tried changing the ezi2c rate, tried changing the frequency at which im sending information and got nothing, it keeps happening.
Was wondering if anyone can give me any help.
Board - PSOC5LP-059
This is my main code:
void Initialize(void)
{
CyGlobalIntEnable; // Uncomment this line to enable global interrupts.
UART_1_Start();
CyDelay(100);// waiting for clear start after power on
UART_1_PutCRLF(' ');
UART_1_PutString("Temperature sensor Maxim DS18B20:\r\n");
DS18x8_1_Start();
ADC_Start();
//void I2C_SlaveInitReadBuf(uint8 * rdBuf, uint8 bufSize);
//void I2C_SlaveInitWriteBuf(uint8 * wrBuf, uint8 bufSize);
//I2C_slave_Start();
EZI2C_SetBuffer1(sizeof(rdBuf), 8, rdBuf);
EZI2C_Start();
temp_interrupt_StartEx(isr_Timer);
}
int main()
{
Initialize();
char tempFloatToArray[4];
flag_Timer = 1; // force first measument instantly
float temp_read;
float voltage_read, current;
uint8 i;
uint8 activity;
for(;;)
{
voltage_read = convert_current();
current = (voltage_read-2.5)/current_sensitivity;
temp_read=read_temperature(); // returns a float with the temperature
memcpy(&tempFloatToArray, &temp_read, sizeof(tempFloatToArray)); //transforms the float into a char array with 4 bytes
if(temp_read != -1000){ //reading of temp was correct
activity=EZI2C_GetActivity();
if((EZI2C_GetActivity() & EZI2C_STATUS_BUSY)==0){ //fill the buffer only when it is not being accessed
UART_1_PutString("ENTREI NO IF**************\r\n");
for(i=0;i<sizeof(tempFloatToArray);i++){
rdBuf=tempFloatToArray;
}
}
}
}
}
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
bump?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Weekend and missing definitions may have delayed an answer. 😉
Can you please post your complete PSoC5 project so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bad error!
In DS18x8_1_GetTemperatureAsString() you return a pointer to a local (automatic) variable. When the function ends the variable (which was allocated on the stack) will get overwritten.
Way out: Declare TempStr as "static" or use it as a global variable.
Check the size of 8 * TempStr against the size of strMsg in main()
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
I changed it to static, but that function is only so I can see the temperature values on the tera term monitor, so it hasn't really been an issue so far as they are being read correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another bump because I am truly lost
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
So I managed to get it working with more loops by changing the pull up resistor value to the standard 4.7k ohm. By having it in default data rate mode (100k bitrate) I can realiably send like 10-15 values and then the problem comes back, it just does not detect the slave response anymore and the master can't get any results.
Is there anyway I can debug this in depth? So far I can only print values, maybe if I can read the clock and data lines I will be able to pinpoint the issue.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please post actual project.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Bob.
In the original post I attached the zip with the full project.
If needed I can also provide the code that I am using on the ESP32 master device.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I understood you made a few changes on the PSoC side project. So I asked for actual project.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure I understand. You mean pictures of the actual implementation in the breadboard? Or the project itself rather than the full workspace?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, double language barrier 😉
I am asking for the actual PSoC workspace.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In DS18x8_1_GetTemperatureAsString() you still return a pointer (result) to a local variable which will get destroyed at return.
The parameters for EZI2C_SetBuffer1() are not correct, see datasheet.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the help bob.
I'm only using that function to print the temperature values in the UART so I can see them in the tera term. I believe it's fine if they get deleted once the function ends, I only need them while printing them on the terminal.
Not sure about what was wrong with my EZI2C buffer but I went and checked the datasheet again and changed it to this:
#define RD_BUFFER_SIZE (0x10u) //16 in decimal
#define RW_BUFFER_SIZE (0x0Cu) //12 in decimal
uint8 rdBuf[RD_BUFFER_SIZE];
EZI2C_SetBuffer1(RD_BUFFER_SIZE, RW_BUFFER_SIZE, rdBuf);
My idea is to have a 16 space buffer where 12 slots are for read/write and 4 are read only, as my master is only requesting 4 bytes of info. Am I thinking wrong here? I'm assuming, by the datasheet, that all the resets to the buffer positions are done automatically by the function calls… Maybe im missing something here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An error remains an error, correct that bug! When an interrupt fires in the midst of the access the result is pretty unpredictable!
"resets to the buffer positions are done automatically by the function calls" Not quite. The I2C master is responsible for addressing the buffer correctly. See pictures in datasheet concerning the sub-address.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
According to the datasheet, the addressing is done by setting the offset data pointer which is the first byte in a write operation. I'm not doing any write operation, my master is only doing read operations. So to send a data read request I need to first do a write with the offset data pointer so I can start doing a read from that position on? Is that it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So to send a data read request I need to first do a write with the offset data pointer so I can start doing a read from that position on? Is that it? That's exactly how I understood the documentation.
From datasheet:
Typically, a read will contain a write operation of only the offset data pointer followed by a restart
(or stop/start) and then the read operation. If the offset data pointer does not require update, as
in the case of repeatedly reading the same data, no additional write operations are required after
the first. This greatly speeds read operations by allowing them to directly follow each other
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much, it finally worked. Appearently you need to fill the WHOLE R/W buffer array with random junk so the EZI2C module thinks it's the data pointer. Only then it will be able to read correctly the size of the read buffer.
Thank you so much for the help, I was really just being an idiot while consulting the datasheet, it seems like whoever wrote it expects you to usually write AND read on the same action, hence not saying anything about only reading.