User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough
Contact: Website

Kernel Panic - i2c

Thu May 30, 2013 1:21 pm

Hi all,

This has happened to me twice today and I have no idea why. Both times bugger the SD card so I have to flash and start from scratch. Ubuntu doesn't recognise it (timeout error 110 on dmesg) so I can't do fsck to repair.

Can anyone spot the error? I assume it's a memory addressing issue??

My code is below on python 2.7...

Code: Select all

import smbus
import time
import sys

bus = smbus.SMBus(0)

def read(add,ch):
   bus.write_byte(add,ch)
   dataIn = bus.read_block_data(add,ch)
   msb = dataIn[1]
   lsb = dataIn[2]
   config = dataIn[3]

   while config & 128:
      dataIn = bus.read_block_data(add,ch)
      msb = dataIn[1]
      lsb = dataIn[2]
      config = dataIn[3]

   adc = msb<<8 | lsb
   return adc

while True:
   print '\r1={}'.format(read(0x68,0x98))
   print '\t2={}'.format(read(0x68,0xB8))
   print '\t3={}'.format(read(0x68,0xD8))
   print '\t4={}'.format(read(0x68,0xF8))

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

Re: Kernel Panic - i2c

Thu May 30, 2013 2:52 pm

Which ADC chip are you using ?

Why are you setting up msb, lsb and config with RANDOM data at start of your function before assigning values to the array values being read. Then using a random value for your while loop control variable.

If you want only four bytes and ignore the first pass an additional parameter to the bus.read_block_data(add,ch) something like

Code: Select all

bus.read_block_data(add,ch,4)
Check the smbus module for that.

Remember array index start at 0
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

Return to “Python”