lwd8cmd
Posts: 8
Joined: Thu Jun 06, 2013 2:36 pm

SPI clock signal ignored

Thu Jun 06, 2013 2:40 pm

Hi,

I'm using Raspberry Pi to communicate with IR thermometer via SPI bus. Device supports 2kHz (raspberry hardware SPI doesn't accept so low frequency so I generated clock pulse with software). Using 2kHz clock I'm losing some bits, with 1kHz I'm getting 2x less useful bits (bits surrounded by many digital high signal) and with 4kHz bits are mostly doubled. Even if Raspberry pi is not sending clock signal, IR thermometer sends it's data using 2kHz.

When data is oversampled I can restore original data and display temperature so data output is correct, just SPI clock signal is ignored.

Why is my clock signal ignored and how is it possible that SPI communication works without clock?

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: SPI clock signal ignored

Fri Jun 07, 2013 1:23 pm

lwd8cmd wrote:Hi,

I'm using Raspberry Pi to communicate with IR thermometer via SPI bus. Device supports 2kHz (raspberry hardware SPI doesn't accept so low frequency so I generated clock pulse with software). Using 2kHz clock I'm losing some bits, with 1kHz I'm getting 2x less useful bits (bits surrounded by many digital high signal) and with 4kHz bits are mostly doubled. Even if Raspberry pi is not sending clock signal, IR thermometer sends it's data using 2kHz.

When data is oversampled I can restore original data and display temperature so data output is correct, just SPI clock signal is ignored.

Why is my clock signal ignored and how is it possible that SPI communication works without clock?
Do you have a link to the data sheet for the IR thermometer?

-Gordon
--
Gordons projects: https://projects.drogon.net/

lwd8cmd
Posts: 8
Joined: Thu Jun 06, 2013 2:36 pm

Re: SPI clock signal ignored

Sat Jun 08, 2013 10:09 am

Thanks for a reply.

I don't have its datasheet and there aren't any compay name or logo on the device. On the PCB there were headers named AGCDV, googling "AGCDV" gave datasheet http://www.zytemp.com/products/files/TN ... al_012.pdf

Made connections: A->GND, G->GND, C->GPIO2, D->GPIO3, V->3.3V

Thankfully my thermometer uses same message format so with a little Python script I'm able to display temperature. Current script doesn't send clock signal, takes readings 8kHz and saves how many sequential readings had the same value. For example sampling digital signal "0110100" would result [4,8,4,4,8] and I can restore original signal without relying on SPI sync. Still, some messages (~3%) are lost, I guess when some background program uses resources, my sample frequency lowers and instead of 8 digital 0 signals I get 5 and one bit is lost.

It would be much easier and reliable if data timing would depend on my clock signal. BTW, shouldn't slave device send no information if clock signal is not present?

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: SPI clock signal ignored

Sat Jun 08, 2013 10:48 am

lwd8cmd wrote:Thanks for a reply.

I don't have its datasheet and there aren't any compay name or logo on the device. On the PCB there were headers named AGCDV, googling "AGCDV" gave datasheet http://www.zytemp.com/products/files/TN ... al_012.pdf

Made connections: A->GND, G->GND, C->GPIO2, D->GPIO3, V->3.3V
Brief look suggests the 'A' pin is their 'ACTION' pin which is their version of the SPI Slave Select signal, dont GND this signal connect it to the correct Slave Select signal from the Pi
Thankfully my thermometer uses same message format so with a little Python script I'm able to display temperature. Current script doesn't send clock signal, takes readings 8kHz and saves how many sequential readings had the same value. For example sampling digital signal "0110100" would result [4,8,4,4,8] and I can restore original signal without relying on SPI sync. Still, some messages (~3%) are lost, I guess when some background program uses resources, my sample frequency lowers and instead of 8 digital 0 signals I get 5 and one bit is lost.

It would be much easier and reliable if data timing would depend on my clock signal. BTW, shouldn't slave device send no information if clock signal is not present?
I suspect you have not soldered wires and with the device permanently selected any noise or intermittent connection is giving extra clock pulses and that is why it is continuously running.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: SPI clock signal ignored

Sat Jun 08, 2013 11:23 am

How are you doing the software 2kHz clock?
You could implement a software SPI by bit-bashing gpio lines for clock and data, ignoring the SPI hardware functions.
Is that what you mean? You may have issues with inconsistent clock frequency.

According to this blog the Pi will only run as bus master on SPI, so the PI end of the bus runs at whatever you program on the Pi, irrespective of what clock you feed to the peripheral.
The Raspberry Pi only implements master mode at this time and has 2 chip-select pins, so can control 2 SPI devices. (Although some devices have their own sub-addressing scheme so you can put more of them on the same bus)
If you feed a different clock to a peripheral it will output data at the wrong speed and presumably un-synchronised.

lwd8cmd
Posts: 8
Joined: Thu Jun 06, 2013 2:36 pm

Re: SPI clock signal ignored

Sun Jun 09, 2013 1:41 pm

techpaul wrote:Brief look suggests the 'A' pin is their 'ACTION' pin which is their version of the SPI Slave Select signal, dont GND this signal connect it to the correct Slave Select signal from the Pi
Yes, A is actionpin with active low. For testing purposes connecting this to the ground should be equivalent with connecting this to the slave select signal and pulling this low.
techpaul wrote:I suspect you have not soldered wires and with the device permanently selected any noise or intermittent connection is giving extra clock pulses and that is why it is continuously running.
I soldered male pins to the thermometer PCB and inserted it to the breadboard. Also, data output is 2kHz, noise frequency should be random.
PiGraham wrote:How are you doing the software 2kHz clock?
You could implement a software SPI by bit-bashing gpio lines for clock and data, ignoring the SPI hardware functions.
Is that what you mean? You may have issues with inconsistent clock frequency.
Python testing code:
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)# action
GPIO.setup(3, GPIO.OUT)# clock
GPIO.setup(2, GPIO.IN)# data
GPIO.output(4, False)# action pin is active low

start = time.time()
res = ''
for x in range(2000):# measure 2k in 1s
GPIO.output(3, True)# clock up
time.sleep(0.00025)
GPIO.output(3, False)# clock down
res += ('1' if GPIO.input(2) else '0')#
time.sleep(0.00025)
print(time.time() - start)# tune sleep time so time diff would be 1s

with open('spi.txt', 'w') as myfile:
myfile.write(res)
edit: Thank you for your comment. Set clock pin to input and saved it's states, turns out thermometer sends clock signal. Datasheet didn't mention it acts as a master, I assumed Raspberry should send clock signal. Although Raspberry don't have hardware SPI slave support, I guess I can write my own code using Raspberry as a slave.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: SPI clock signal ignored

Sun Jun 09, 2013 3:41 pm

If the device is a master then you can either write a software slave SPI or in long term more reliable using external logic or PLD create your own 'SPI bridge'. Data in from TN09 Data out to Pi.

Basically a long shift register capable of holding one complete message, when Action is LOW you use logic gates to route the Clock from the TN09 to the shift register. When action is HIGH and slave select LOW route clock from Pi to the shift register.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

edo.rap90
Posts: 2
Joined: Thu Oct 31, 2019 5:00 pm

Re: SPI clock signal ignored

Sun Nov 03, 2019 4:02 pm

Hi, I know that this topic is quite old but I'm facing some problems controlling the TN9 with a Raspberry Pi Zero W.

I know how to read TN9 data using Arduino but I'd like to do something similar using a RPi.
Before trying to port the TN9 Arduino scripts on the RPi I'd like to know if someone already did something on this direction.

Many thanks!

edo.rap90
Posts: 2
Joined: Thu Oct 31, 2019 5:00 pm

Re: SPI clock signal ignored

Mon Nov 11, 2019 5:16 pm

I translated to Python the Freetronics IRTemp Arduino library (https://github.com/freetronics/IRTemp), using WiringPi (http://wiringpi.com) and WiringPi-Python (https://github.com/WiringPi/WiringPi-Python) in order to use the TN9 sensor with a Raspberry Pi.

Here is the code: https://github.com/edrap/TN9

Return to “Interfacing (DSI, CSI, I2C, etc.)”