XPT2041 & SPI Conflict

For general Flowcode discussion that does not belong in the other sections.
jollybv
Posts: 125
http://meble-kuchenne.info.pl
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

XPT2041 & SPI Conflict

Post by jollybv »

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
Boot ESP32-2.txt
(3.43 KiB) Downloaded 62 times

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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: XPT2041 & SPI Conflict

Post by BenR »

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.

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Re: XPT2041 & SPI Conflict

Post by jollybv »

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.
ili9341_Test_touch1.fcfx
(135.89 KiB) Downloaded 62 times

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: XPT2041 & SPI Conflict

Post by BenR »

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.

Code: Select all

Main Loop
{
  Init XPT2041
  Read XPT2041
  ....
  Init MAX6675
  Read Max6675
  ...
}
Would something like this work?

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Re: XPT2041 & SPI Conflict

Post by jollybv »

Hi Ben

Is the below code what you mean as I have tried it and does not work
XPT2046.PNG
XPT2046.PNG (46.83 KiB) Viewed 2075 times

SPI Max6675.PNG
SPI Max6675.PNG (26.61 KiB) Viewed 2075 times

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Re: XPT2041 & SPI Conflict

Post by jollybv »

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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: XPT2041 & SPI Conflict

Post by BenR »

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?

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Re: XPT2041 & SPI Conflict

Post by jollybv »

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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: XPT2041 & SPI Conflict

Post by BenR »

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.

jollybv
Posts: 125
Joined: Mon Mar 08, 2021 11:25 am
Location: Cape Town South Africa
Has thanked: 40 times
Been thanked: 11 times

Re: XPT2041 & SPI Conflict

Post by jollybv »

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.

MAX6675.jpg
MAX6675.jpg (20.1 KiB) Viewed 2011 times

Post Reply