PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1616
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Thu Nov 30, 2017 5:20 pm

We'll need a bit more information:
1. Which AD device is it?
2. Which application/script is reading it? A link to the source would help.
3. What were you upgrading from?
4. Can you show spidev_test output before and after the upgrade? You can download previous Raspbian releases here.

monkijohnni
Posts: 5
Joined: Tue Nov 28, 2017 7:16 am
Location: Portland, OR
Contact: Website

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Thu Nov 30, 2017 8:06 pm

Thank you for the fast reply!

1. I'm just using an MCP3008 AD chip, so nothing too complicated. A PT100 thermistor is talking to it on CH0.

2. Here is my code:

Code: Select all

#!/usr/bin/python3
 
import spidev
import time
import os
 
spi = spidev.SpiDev()
spi.open(0,0)
 
# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data
 
def ConvertVolts(data,places):
  volts = (data * 3.3) / float(1023)
  volts = round(volts,places)
  return volts
 
def ConvertTemp(data,places):
  temp = (0.972*(data))-359
  temp = round(temp,places)
  return temp
 
temp_channel  = 0
delay = 5
 
while True:
  temp_level = ReadChannel(temp_channel)
  temp_volts = ConvertVolts(temp_level,6)
  temp       = ConvertTemp(temp_level,6)
 
  print "--------------------------------------------"
  print("Temp : {} ({}V) {} deg C".format(temp_level,temp_volts,temp))
 
  time.sleep(delay)
  
3. I was apt-get upgrade(ing) from the 2017-09-07 RASPBIAN STRETCH WITH DESKTOP image (still most current). Very little had been changed to the image since downloading and flashing it to the SD card EXCEPT that I had set up some localization preferences, and I apt-get update(d) prior to running apt-get upgrade.

4. I'll do this when I get home tonight (sorry)...

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1616
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Thu Nov 30, 2017 8:59 pm

You can hold off on 4 for a bit until we've ruled out the obvious cause (or not).

A recent change to the SPI subsystem was to increase the maximum bus speed (it was artificially low before). Unfortunately, the default bus speed for transfers is set to the maximum allowed, so applications that don't set a speed will likely end up with something unusable.

Try setting the max_speed_hz property to something sensible:

Code: Select all

      spi = spidev.SpiDev()
      spi.open(0,0)
      spi.max_speed_hz=1000000

monkijohnni
Posts: 5
Joined: Tue Nov 28, 2017 7:16 am
Location: Portland, OR
Contact: Website

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Thu Nov 30, 2017 11:36 pm

EDITED: lowering bus speed fixed it.

Increasing the bus speed seem to fix it. I included the spi.max_speed_hz=1000000 in my code, and got feedback from SPI.

Code: Select all

#!/usr/bin/python3
 
import spidev
import time
import os
 
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=1000000

....

Seems that going over 10,000,000 started to interfere with the readings I got back. I'm going to stick with 1,000,000.
Last edited by monkijohnni on Fri Dec 01, 2017 4:05 pm, edited 1 time in total.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1616
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Fri Dec 01, 2017 9:21 am

Apart from dropping the speed right down - 100000 or lower, for example - I'm not sure what to suggest.

monkijohnni
Posts: 5
Joined: Tue Nov 28, 2017 7:16 am
Location: Portland, OR
Contact: Website

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Fri Dec 01, 2017 4:10 pm

My last post was incorrect. Setting the bus speed DID fix the SPI problem, I just was getting incorrect results because of a wiring error (was working remotely).

Seems that any bus speed under 10,000,000 works well. Thank you so much for your help, PhilE! I really appreciate it.
-John

Code: Select all

#!/usr/bin/python3
 
import spidev
import time
import os
 
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=1000000

...
...

Infinity48
Posts: 3
Joined: Sun Jan 28, 2018 10:41 am
Contact: Website

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Mon Apr 02, 2018 5:26 pm

When I enable SPI, it crashes and then when I reboot, SPI is off!
Please help me!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1616
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Mon Apr 02, 2018 6:14 pm

1. Which Pi are you using?
2. Which Operating System (with a version number)?
3. How do you enable SPI?
4. Does it crash immediately, or do you have to attempt to use SPI before it will crash?

andminsk
Posts: 4
Joined: Thu Mar 22, 2018 5:16 pm

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Sun Apr 08, 2018 5:26 pm

Dear colleagues, I have a strange problem with i2c and Pi3 (Raspbian)

I made a well-known project with MPU6050 accelerometer (GY-521 module) with well-known script
https://tutorials-raspberrypi.com/measu ... pberry-pi/

And it worked at morning.
Afternoon it starts to show this error

pi@raspberrypi:~ $ python3 accel.py
Reading Data of Gyroscope and Accelerometer
Traceback (most recent call last):
File "accel.py", line 61, in <module>
acc_y = read_raw_data(ACCEL_YOUT_H)
File "accel.py", line 38, in read_raw_data
high = bus.read_byte_data(Device_Address, addr)
OSError: [Errno 121] Remote I/O error


Although I can see the sensor at i2cbus:

pi@raspberrypi:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --


and can read registers:

pi@raspberrypi:~ $ sudo i2cget -y 1 0x68 0x75
0x68
pi@raspberrypi:~ $ sudo i2cget -y 1 0x68 0x0d
0x4b
pi@raspberrypi:~ $ sudo i2cget -y 1 0x68 0x75
0x68

I tried this with 2 GY-521 modules, they are working at same manner.
Nothing was changed since morning, all worked fine before (although sometimes MPU6050 script stopped operation with error, don't know exactly which one because it is rarely happened before).


May be you can give some advices. ... thanks!

andminsk
Posts: 4
Joined: Thu Mar 22, 2018 5:16 pm

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Mon Apr 09, 2018 6:53 pm

it seems these GY-521 modules gonna die fast.
I manage to get some data when deleted all gyro and axis reading, left only one axis.
But after several measurements receive same error again.

Which MPU6050 module you can recommend? for fast connection preferably..

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1616
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: STICKY:I2C, SPI, I2S, LIRC, PPS, stopped working? Read this.

Mon Apr 09, 2018 6:55 pm

By burying your question at the end of a long thread you will miss most of the potential audience. Create a new topic instead with a meaningful title.

Return to “Troubleshooting”

Who is online

Users browsing this forum: HawaiianPi, PeterO and 24 guests