Hi Guys
Having a little bit of an issue with the initialization of the XPT2046 & the SPI component if I initialize the XPT2046 before the SPI then the SPI works and XPT2046 dose not work. I am get this message when booting the ESP32 not sure if it is relevant.
(411) spi: spi_bus_initialize(628): SPI bus already initialized
If I inisalize the other way around the SPI then XPT2046 then the SPI (max6675) then what I have to do is remove the power to Max6675 boot then put power back and the XPT2046 touch screen works but the SPI bus only reads the max6675 once.
I am rinning the XPT2046 and The Max6675 on the same SPI bus
XPT2041 & SPI Conflict
-
- Posts: 136
- http://meble-kuchenne.info.pl
- Joined: Mon Mar 08, 2021 11:25 am
- Location: Cape Town South Africa
- Has thanked: 41 times
- Been thanked: 12 times
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: XPT2041 & SPI Conflict
Hello,
SPI can run in 4 different modes to do with the clock polarity and phase. Normally a slave device will be compatible with at least two of the modes.
https://www.analog.com/en/analog-dialog ... rface.html
If the two devices you're using have conflicting modes then it could be enabling the second device is causing the first device to fail as the SPI will be outputting in the wrong mode format for the first device.
One option would be to use software SPI as this would output in the right mode for the component.
Another option would be to write to the register that controls the SPI mode before communicating with each device and this would maybe allow you to use hardware to talk to both in turn.
SPI can run in 4 different modes to do with the clock polarity and phase. Normally a slave device will be compatible with at least two of the modes.
https://www.analog.com/en/analog-dialog ... rface.html
If the two devices you're using have conflicting modes then it could be enabling the second device is causing the first device to fail as the SPI will be outputting in the wrong mode format for the first device.
One option would be to use software SPI as this would output in the right mode for the component.
Another option would be to write to the register that controls the SPI mode before communicating with each device and this would maybe allow you to use hardware to talk to both in turn.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 136
- Joined: Mon Mar 08, 2021 11:25 am
- Location: Cape Town South Africa
- Has thanked: 41 times
- Been thanked: 12 times
Re: XPT2041 & SPI Conflict
Hi Ben
I have tried to do both SPI devices in software with no luck. If I read the max6675 in software mode then at 18° it reads 43° if I read the max6675 chanel 1 SPI it reads correct but only reads once. My last option would be to write to the register that controls the SPI.
How do i do that? Please help as this is the last obstacle then I can design PCB.
I have attached some of the program maybe I'm doing something wrong that I cant see but by now I'm pretty sure I have done every thing right.
I have tried to do both SPI devices in software with no luck. If I read the max6675 in software mode then at 18° it reads 43° if I read the max6675 chanel 1 SPI it reads correct but only reads once. My last option would be to write to the register that controls the SPI.
How do i do that? Please help as this is the last obstacle then I can design PCB.
I have attached some of the program maybe I'm doing something wrong that I cant see but by now I'm pretty sure I have done every thing right.
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: XPT2041 & SPI Conflict
Hello,
The best way to do this on the ESP32 device might be to call the initialise function when you come to do the comms and this should put the SPI back into the correct mode.
For example.
Would something like this work?
The best way to do this on the ESP32 device might be to call the initialise function when you come to do the comms and this should put the SPI back into the correct mode.
For example.
Code: Select all
Main Loop
{
Init XPT2041
Read XPT2041
....
Init MAX6675
Read Max6675
...
}
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 136
- Joined: Mon Mar 08, 2021 11:25 am
- Location: Cape Town South Africa
- Has thanked: 41 times
- Been thanked: 12 times
Re: XPT2041 & SPI Conflict
Hi guys
I had a good weekend of programming my project is finished the only issue is the clashing with the XPT2046 touch sensor and the SPI bus (max6675) please is there any help on how i can resolve this. The XPT2046 touch sensor is working like a dream but the MAX6675 only reads once
I had a good weekend of programming my project is finished the only issue is the clashing with the XPT2046 touch sensor and the SPI bus (max6675) please is there any help on how i can resolve this. The XPT2046 touch sensor is working like a dream but the MAX6675 only reads once
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: XPT2041 & SPI Conflict
Hello,
Aha I thought the SPI pins were shared with another component but they aren't they are just for the temperature sensor so it's strange. I've looked at the ESP32 problem pins and the pins your currently using look like they should be fine.
It could be a timing problem, the datasheet for the MAX device states the conversion time is 170 - 220ms and in your program there is a delay but it's only 50ms. The datasheet says if you jump in and do a read before the conversion is complete then conversion will be terminated so maybe you're trying to sample the device too fast?
Aha I thought the SPI pins were shared with another component but they aren't they are just for the temperature sensor so it's strange. I've looked at the ESP32 problem pins and the pins your currently using look like they should be fine.
It could be a timing problem, the datasheet for the MAX device states the conversion time is 170 - 220ms and in your program there is a delay but it's only 50ms. The datasheet says if you jump in and do a read before the conversion is complete then conversion will be terminated so maybe you're trying to sample the device too fast?
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 136
- Joined: Mon Mar 08, 2021 11:25 am
- Location: Cape Town South Africa
- Has thanked: 41 times
- Been thanked: 12 times
Re: XPT2041 & SPI Conflict
Hi Ben
Thanks that worked I put a 250ms delay after I read the max6675 and before i do the calculations. It is now reading just it is reading 41 degrees and should be 21 so its 20 degrees out. I can subtract 80 from RawData and correct it but 20 degrees is a bit excessive
Thanks that worked I put a 250ms delay after I read the max6675 and before i do the calculations. It is now reading just it is reading 41 degrees and should be 21 so its 20 degrees out. I can subtract 80 from RawData and correct it but 20 degrees is a bit excessive
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: XPT2041 & SPI Conflict
Hmm your code to do the temperature bit shifting looks ok to me but that error seems very large.
Are you using a type -K thermocouple?
How are you connecting from the IC to the thermoucouple? it is making a good connection and is there other bi-metal action going on that could be effecting your readings? I think we use good quality screw terminals here to join to the thermocouple wire and that works fairly well.
Are you using a type -K thermocouple?
How are you connecting from the IC to the thermoucouple? it is making a good connection and is there other bi-metal action going on that could be effecting your readings? I think we use good quality screw terminals here to join to the thermocouple wire and that works fairly well.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 136
- Joined: Mon Mar 08, 2021 11:25 am
- Location: Cape Town South Africa
- Has thanked: 41 times
- Been thanked: 12 times
Re: XPT2041 & SPI Conflict
Hi Ben
I'm using a Max6675 breakout board a K probe and the connections seems good to me. I have 2 of these boards and they both doing the same.
I'm using a Max6675 breakout board a K probe and the connections seems good to me. I have 2 of these boards and they both doing the same.