Coder Social home page Coder Social logo

py-spidev's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py-spidev's Issues

Subclass-ability

Playing around with your module I wanted to create a subclass of the SpiDev class, but found it impossible. After some poking around Python docs I added a Py_TPFLAGS_BASETYPE flag and all seems to be fine and my app works. Not sure is that's all that needs to be done ...
Since it's only a one line change, didn't want to create a full blown pull request so here's the diff :

diff --git a/spidev_module.c b/spidev_module.c
index f39a761..c9413aa 100644
--- a/spidev_module.c
+++ b/spidev_module.c
@@ -798,7 +798,7 @@ static PyTypeObject SpiDevObjectType = {
        0,                              /* tp_getattro */
        0,                              /* tp_setattro */
        0,                              /* tp_as_buffer */
-       Py_TPFLAGS_DEFAULT,             /* tp_flags */
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,               /* tp_flags */
        SpiDevObjectType_doc,           /* tp_doc */
        0,                              /* tp_traverse */
        0,                              /* tp_clear */

Please let me know if you see merging this into master as a workable idea. Thanks !

Cheers,

Teo

"with" statement support

I've been searching for some documentation to implement with statement support for SpiDev and couldn't find much.
Is there interest in adding this feature? If you point me some directions I can create a PR for that.

xfer2 deassert the csline after transfer

hello
xfer and xfer2 have the same behaviour
i needed to transfer two block while keeping the csline low between them
doing so i used xfer2 for first block then xfer for second block,
but the csline goes high between

thanks for supporting py-spidev
AM

silent failure in python when using xfer() and xfer2()

I recently tried running this code:
import sys import spidev spi_bus = spidev.SpiDev() exit_code = spi_bus.open(0, 0) print('getting the adc output ') adc_output = spi_bus.xfer2(1, 240, 0 ) print('adc read complete')

The code would get to the xfer2() and the just stop and return to the prompt with no error or warning.

The bug in the above code is that there should have been brackets around the list passed to xfer2() as shown below.

import sys import spidev spi_bus = spidev.SpiDev() exit_code = spi_bus.open(0, 0) print('getting the adc output ') adc_output = spi_bus.xfer2([1, 240, 0] ) print('adc read complete')

Ideally SpiDev.xfer2() would have generated some type of error or warning rather than have the whole program just stop without an error message.

Note: I am a newbee so I do not even know if it is possible to do what I am suggesting. However, if you can, it would sure save the next person to hit the problem a lot of effort.

AT91SAM9260 SPI Protocol Error during SPI transfer

I used the py-spidev library in AT91SAM9260 board. I got the error IOError: [Error 92]: Protocol not available during SPI transfer. The problem was actually caused due to the Atmel SPI driver not supporting per transfer setting of speed and bits_per_word. So this quick fix in spidev_module.c solved the problem for me. I set the following variables in the xfer function to zero.


+   xfer.speed_hz = 0;
+   xfer.bits_per_word = 0; 

Is there a better fix for this problem? I would like to contribute a proper patch for this issue. Thank you.

IOError: [Errno 24] Too many open files

When implemented for a large stream of data to send, the script crashes with "IOError: [Errno 24] Too many open files".

Method of implementation is:
def SendSong(bytes):
speed = 2500000
print("Sending packets . . . ")
while(len(bytes) > 0):
if(len(bytes) > 4096):
SPI_sendPackets(bytes[:4096], speed)
bytes_read = bytes[4097:]
else:
SPI_sendPackets(bytes_read, speed)
bytes_read = list()

def SPI_sendPackets(listOfPackets, speed):
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = speed

spi.xfer2(listOfPackets)

set mode for each device individual

Here is an example of our problem:

import spidev
spi1 = spidev.SpiDev()
spi1.open(1, 0)
spi1.mode=1

spi1.xfer([0xFF]) # will transmit with mode=1

spi2 = spidev.SpiDev()
spi2.open(1, 1)
spi2.mode=2

spi2.xfer([0xFF]) # will transmit with mode=2

### and now the problem
spi1.xfer([0xFF]) # will transmit with mode=2 and not with mode=1 as indented

the .mode attribute is available correctly:

>>> spi1.mode
1
>>> spi2.mode
2

So mode (and max_speed_hz, ...) should be written in readbytes, writebytes, xfer, ...

We're willing to deliver a patch if this feature/bugfix(?) is desired. I'm afraid it could possibly break code if the actual behavior is expected.

xfer modifies its input list

xfer() function modifies the list of values that you give it as input. This was totally unexpected and a bit annoying.

>>> a = [0, 1, 2, 3]
>>>spi.xfer(a)
[0, 0, 0, 0]
>>> a
[0, 0, 0, 0]

So basically, it sends the 4 bytes (0, 1, 2, 3) and the host reply was 4 zeros. The problem is that it also modifies the input parameter, list a, with the SPI data that was read in. And the function also returns the same data.

Either it should return the data read in over SPI and not modify the input, or it should modify the input list and not return anything, but it should not do both.

If it had no return, then it is more obvious that the SPI data read in would be in the input list, basically a buffer exchange, which is what SPI is. But because it also returns the SPI read data, it makes one think it is a regular function.

A simple way to get around this is to convert the data to a tuple first so it cannot be modified:

spi.xfer(tuple(a))

Anyway, behavior should be clearly documented.

max_speed_hz does not work

Hi,

I'm using spidev to communicate with LCD displays.
I found that setting max_speed_hz has no effect on the actual SPI speed which continues to run at 64Mhz.

Kernel: 4.1.21-v7+

How to write to a specific address

Greetings,

I'm trying to use py-spidev to communicate with a "HopeRF RFM31B".

I can read the registers fine.

I cannot write data to a specific address using writebytes(...) or xfer(...)

How to do this?

Many thanks in advance,

install error

hi
when that i install setup.py
sudo python setup.py install
error :
r```
unning install
running build
running build_ext
building 'spidev' extension
creating build
creating build/temp.linux-armv7l-2.7
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c spidev_module.c -o build/temp.linux-armv7l-2.7/spidev_module.o
spidev_module.c:20:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

All xfer2()s on MCP3008 return "TypeError: Argument must be a list of at least one, but not more than 4096 integers"

I have followed numerous guides (that all agree) to wire up the MCP3008. I breadboarded a simple pot sensing circuit. The spidev/spi_bcm{2708,2835} drivers are installed and I tested MISO/MOSI with a direct test. But I always get this message.
Traceback (most recent call last):
File "adafruit_mcp3008-spi.py", line 56, in
trim_pot = readadc(potentiometer_adc)
File "adafruit_mcp3008-spi.py", line 36, in readadc
r = spi.xfer2(commandout)
TypeError: Argument must ...

My test code: https://gist.github.com/timwood0/5e13fac6db4493cf4c85

BTW spidev_module.c confusingly uses the same error message for several different error cases!

Anyone see anything obviously wrong? I tried running with tomstokes/python-spi library; the test reports bursts of noise values on the A/D output using that stack.

no_cs option doesn't work.

Hi,

I've tried to set the no_cs option True in order to disable te Chip Select but it is still active. Am I doing something wrong? Thanks.

Guiem

spi.lsbfirst = True fails with [Errno 22] Invalid argument

This is related to #18

The above issue is what happens when an unraised exception leaks via the interpreter and is assumed to have been raised by a method from another library.

This issue is to deal with the exception itself- ie: why does spi.lsbfirst = True raise an Invalid Argument from __spidev_set_mode?:

static int __spidev_set_mode( int fd, __u8 mode) {
    __u8 test;
    if (ioctl(fd, SPI_IOC_WR_MODE, &mode) == -1) {
        PyErr_SetFromErrno(PyExc_IOError);
        return -1;
    }
    if (ioctl(fd, SPI_IOC_RD_MODE, &test) == -1) {
        PyErr_SetFromErrno(PyExc_IOError);
        return -1;
    }
    if (test != mode) {
        return -1;
    }
    return 0;
}

How to add delay between tranfer

i use your project to make a communication between Raspberry Pi (MASTER) and AVR (SLAVE). I noticed the data from raspberry is sucessfully sent but the data from AVR only the first communication success. Rest of the byte is read as what i send, i think AVR don't have enough time to to change SPI Data Register or SPDR before being read by the Raspberry.
so i want to add a delay, i found the delay_usec in the spi.xfer but how i change it. thanks

Setting Number of Bits

Hi, I have searched for an answer on this but have not found anything.

Is it possible to set the number of bits (i.e. 9) and the clock frequency from python ?

Relicense

Would it be possible to relicense this project under LGPL or similar?

attribute 'no_cs' not existing with python 3.5

Hi,

this code snipped works with python 2.7:

import spidev

spi = spidev.SpiDev()
spi.open(0, 1)
spi.max_speed_hz = 500000
spi.no_cs = True
print(spi.xfer2([0xFF]))
spi.close()

when beeing executed with python 3.5, it yields the error "AttributeError: 'SpiDev' object has no attribute 'no_cs'".

Python 2.7.13
Python 3.5.3
Raspberry Pi 3, Raspbian Strech , kernel 4.9.59+

tobias

License update

Would you be ok with updating the license to GPLv2 or later? I'm working on some code that I would like to license GPLv3 that uses spidev. Thanks

Build failure: conflicting types for ‘fd_set’ et al.

I'm trying to install for Python 2.7 with kernel 3.18, and I get
dozens of compiler errors (see below). So far, Google hasn't found me any
answers (only people reporting the same problem). Any ideas?


# sudo python setup.py install

running install
running build
running build_ext
building 'spidev' extension
x86_64-pc-linux-gnu-gcc -pthread -fPIC -I/usr/src/linux/include -I/usr/include/python2.7 -c spidev_module.c -o build/temp.linux-x86_64-2.7/spidev_module.o
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:14:26: error: conflicting types for ‘fd_set’
 typedef __kernel_fd_set  fd_set;
                          ^
In file included from /usr/include/sys/types.h:219:0,
                 from /usr/include/stdlib.h:314,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/select.h:75:5: note: previous declaration of ‘fd_set’ was here
   } fd_set;
     ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:15:25: error: conflicting types for ‘dev_t’
 typedef __kernel_dev_t  dev_t;
                         ^
In file included from /usr/include/stdlib.h:314:0,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/types.h:60:17: note: previous declaration of ‘dev_t’ was here
 typedef __dev_t dev_t;
                 ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:19:17: error: conflicting types for ‘nlink_t’
 typedef __u32   nlink_t;
                 ^
In file included from /usr/include/stdlib.h:314:0,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/types.h:75:19: note: previous declaration of ‘nlink_t’ was here
 typedef __nlink_t nlink_t;
                   ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:25:26: error: conflicting types for ‘timer_t’
 typedef __kernel_timer_t timer_t;
                          ^
In file included from /usr/include/sys/types.h:132:0,
                 from /usr/include/stdlib.h:314,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/time.h:103:19: note: previous declaration of ‘timer_t’ was here
 typedef __timer_t timer_t;
                   ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:45:26: error: conflicting types for ‘loff_t’
 typedef __kernel_loff_t  loff_t;
                          ^
In file included from /usr/include/stdlib.h:314:0,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/types.h:44:18: note: previous declaration of ‘loff_t’ was here
 typedef __loff_t loff_t;
                  ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:111:17: error: conflicting types for ‘uint64_t’
 typedef  __u64  uint64_t;
                 ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.4/include/stdint.h:9:0,
                 from /usr/include/inttypes.h:27,
                 from /usr/include/python2.7/pyport.h:9,
                 from /usr/include/python2.7/Python.h:58,
                 from spidev_module.c:20:
/usr/include/stdint.h:55:27: note: previous declaration of ‘uint64_t’ was here
 typedef unsigned long int uint64_t;
                           ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:112:17: error: conflicting types for ‘u_int64_t’
 typedef  __u64  u_int64_t;
                 ^
In file included from /usr/include/stdlib.h:314:0,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/types.h:203:1: note: previous declaration of ‘u_int64_t’ was here
 __u_intN_t (64, __DI__);
 ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:113:17: error: conflicting types for ‘int64_t’
 typedef  __s64  int64_t;
                 ^
In file included from /usr/include/stdlib.h:314:0,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/types.h:197:1: note: previous declaration of ‘int64_t’ was here
 __intN_t (64, __DI__);
 ^
In file included from /usr/include/linux/spi/spidev.h:25:0,
                 from spidev_module.c:25:
/usr/src/linux/include/linux/types.h:134:23: error: conflicting types for ‘blkcnt_t’
 typedef unsigned long blkcnt_t;
                       ^
In file included from /usr/include/stdlib.h:314:0,
                 from /usr/include/python2.7/Python.h:42,
                 from spidev_module.c:20:
/usr/include/sys/types.h:248:22: note: previous declaration of ‘blkcnt_t’ was here
 typedef __blkcnt64_t blkcnt_t;    /* Type to count number of disk blocks.  */
                      ^
spidev_module.c:35:0: warning: "PyLong_Check" redefined [enabled by default]
 #define PyLong_Check(val) PyInt_Check(val)
 ^
In file included from /usr/include/python2.7/Python.h:88:0,
                 from spidev_module.c:20:
/usr/include/python2.7/longobject.h:14:0: note: this is the location of the previous definition
 #define PyLong_Check(op) \
 ^
error: command 'x86_64-pc-linux-gnu-gcc' failed with exit status 1

increased spi buffer sizer

I am using a chip board and I followed these instructions https://bbs.nextthing.co/t/spi-support-on-chip-pro/15150/38 to increase the size of spi buffer from 4096 to 16384. I ran my code and got the following error
Traceback (most recent call last):
File "lights.py", line 98, in
neo.refresh()
File "lights.py", line 82, in refresh
spi.xfer2(stick, 3000000, 0, 8)
TypeError: Non-Int/Long value in arguments: b6cb5e18.

I believe it is because of this line in xfer2
char wrmsg_text[4096];

I tried changing it but it still gave me the error

How to inherit?

I'm trying to inherit spidev library to a custom class. I'm using python2.

This is the code that I'm using:
self.spi = spidev.SpiDev()
self.spi.open(bus,CS)
self.spi.mode = 0
self.spi.lsbfirst = False
self.spi.max_speed_hz = speed

And its tell me that global name 'spi' is not defined. Any suggestions?

Setting lsbfirst = True breaks access to GPIO on Raspberry Pi 1/2 with 3.18 kernel

Apologies if this isn't the right repo but I can't open issues on gadgetoid's fork here (https://github.com/gadgetoid/py-spidev) that appears to be the new master for pyspidev on PyPi (according to http://www.raspberrypi.org/forums/viewtopic.php?f=32&t=98070&p=720659 and #15).

I'm using spidev 3.0 from PyPi and see that opening a spidev device and setting lsbfirst = True causes future access to GPIO (through the RPi.GPIO library) to fail. Here's the simplest example to repro the problem:

import time

import RPi.GPIO as GPIO
import spidev

spi = spidev.SpiDev()
spi.open(0, 0)
spi.lsbfirst = True

# Initialize GPIO23 as an output.
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)

# Set GPIO23 high and then low.
print 'High'
GPIO.output(23, GPIO.HIGH)
time.sleep(1)

print 'Low'
GPIO.output(23, GPIO.LOW)
time.sleep(1)

print 'Done!'

That should open /dev/spidev0.0 with LSB first mode and then blink GPIO23 high and low for a second. However when you run it immediately fails when trying to setup the GPIO:

Traceback (most recent call last):
  File "test2.py", line 13, in <module>
    GPIO.setup(23, GPIO.OUT)
IOError: [Errno 22] Invalid argument

If you comment out the line spi.lsbfirst = True everything works as expected and the GPIO23 line goes high and low without any errors.

This repros for me on a Raspberry Pi 1 or 2 using the latest February 16th, 2015, image which uses kernel 3.18.7.

I haven't really dug in to investigate further but it definitely seems like something is up with the post 3.15 kernel and setting lsbfirst = True.

package extension

I'm implementing a library for the MCP3008 A/D converter chip.
It just implements the example communication protocol in the datasheet inheriting SpiDev.
Is there interest in creating an extension folder for the package to add support for devices like these?

xfer does not de-assert CS between bytes

xfer seems to behave exactly as xfer2, and does not de-assert CS between the bytes of the data to be transmitted. Checked with logic analyzer.

Context: Raspi2, Raspbian, Python 2.7.9

bits_per_word in RasPi problem

Hi there:

I'm using the SpiDev to connect my device and I need to send 16 bits words. I'm using the option "bits_per_word=16". However, if I put a value above 9 bits I recieve the error
"IOError: [Errno 22] invalid argument".

I'm wondering if this is a problem of either the wrapper or the RasPi. I thought that the RasPi register were only 8 bits but it's working with 9 bits words.

Thanks for any feedback!

Mario B.

PyPi Package Abandoned?

I noticed the package on PyPi hasn't been updated since 2012-12-17. A number of people, particularly in the Raspberry Pi community, depend upon this package for SPI access in Python- and as of Kernel 3.15+ it's going to break ( see recent pull request about this ).

Are you able to either:

a) Accept the pull request and publish this package to PyPi

or

b) Turn over the PyPi package to us, so that we can maintain it better for the benefit of all?

Can I set MOSI default HIGH, and set CS low separately for ~1ms?

Hello,
I am doing a project using RPi to talk with Linear LTC6804 (battery monitoring chip) in SPI. I am using Python with spidev module to control SPI communication. However, it looks like the default MOSI pin signal is LOW, while the LTC6804 requests MOSI default HIGH.

See below in good communication the LTC6804 requests MOSI default HIGH. Also before sending request on MOSI, the CS needs to be set LOW for 0.3ms for waking up the chip.
spi_communication_good

See below in bad communication with LTC6804 using functions from spidev with MOSI default LOW. I cannot find how to set MOSI pin default HIGH with spidev.
spi_communication_bad

So see someone can help out:

  1. how can I set MOSI pin default HIGH when using spidev in Python? Or some other ways to achieve that?
  2. how can I set CS pin LOW for ~1ms when still using spidev in Python?
    I want to get exactly the same output from RPi as the first attached screenshot.

Thank you!

How to sets values to differents CS?

Thanks for this amazing library.
I was wondering how can I set values to differents chip select lines due the fact that I'm not sure which line is set when I'm using the property cshigh.
Thanks in advance.

writebytes/readbytes broken?

I connected MISO and MOSI on my RaspberryPI and ran this program:

#!/usr/bin/env python
import spidev
def dmp(A):
    s = ""
    cnt = 0
    for a in A:
        s+="%0.2X " % a
        cnt=(cnt+1)%6
        if cnt == 0:
            s+="\n"
    print s

spi = spidev.SpiDev()
spi.open(0,0)
b = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D]
print "testing read/write bytes"
spi.writebytes(b)
dmp(spi.readbytes(len(b)))
print "testing xfer"
dmp(spi.xfer(b))
print "testing xfer2"
dmp(spi.xfer2(b))
spi.close()

The array b should be echoed, but instead there are only zeroes. I checked writebytes() with an oscilloscope and it seems like it doesn't send anything at all.
But xfer and xfer2 work.

Or have I misunderstood writebytes? I thought it doesn't return anything, but keeps the data in a buffer which is accessable via readbytes.

some other interesting stuff:

$ uname -a
Linux raspberrypi 3.18.9+ #768 PREEMPT Sun Mar 15 18:59:03 GMT 2015 armv6l GNU/Linux
$ modinfo spi-bcm2708 
filename:       /lib/modules/3.18.9+/kernel/drivers/spi/spi-bcm2708.ko
alias:          platform:bcm2708_spi
license:        GPL v2
author:         Chris Boot <[email protected]>
description:    SPI controller driver for Broadcom BCM2708
srcversion:     4C511494EF4EBE6610ACDB6
alias:          of:N*T*Cbrcm,bcm2708-spi*
depends:        
intree:         Y
vermagic:       3.18.9+ preempt mod_unload modversions ARMv6 

Python 3

Are there any plans to port this to Python 3? At present forced to use Python 2 solely due to this extension.

Have attempted porting it myself but couldn't quite get there!

Two's complement output

Hi,

I'd like to return a Two's Complement binary value from SpiDev_readbytes()
How would I go about it? I think it requires modification of the use of rxbuf[]

Delay does not delay in between blocks

It appears that delay_usec delays the chip select deactivation, but nothing else. When sending multiple bytes, there is not delay in between the bytes which is how I interpret the purpose of delay_usec. Is that even the correct interpretation? See image below: Sent two bytes with delay_usec = 9000

issues1

CS line behaves the same with xfer and xfer2

I am having an issue with reading an MPC3004 ADC. It requires the CS line to be held low between the bytes. As you can see in the image below, the CS signal (top line) is going high between bytes.
From: http://ww1.microchip.com/downloads/en/DeviceDoc/21295C.pdf

3.7 Chip Select/Shutdown (CS/SHDN) The CS/SHDN pin is used to initiate communication with the device when pulled low. When pulled high, it will end a conversion and put the device in low power standby. The CS/SHDN pin must be pulled high between conversions.

The line of python3 I'm using is:

spi.xfer([0x01, 0x80, 0x00])

img_20161116_132455

I'm seeing the same behaviour if I do xfer or xfer2.

Is there an issue with xfer2?
Or is my understanding of the difference between xfer and xfer2 wrong?

xfer, xfer2, writebytes wrong handling of longs

If the data to be sent contains items which type is long, they are are sent as 0x01 (checked with a logic analyzer) whatever is their value if they are not null. This is true even if the value fits in 8 bits.

Taking care of "casting" with int() when building the list of values avoids the problem.

Environment: Python 2.7.9 - RasPi2

SPI output stops after first packet on BeagleBone Black

I'm trying to communicate with an LPD8806 strip on my BBB using python and installed py-spidev (which is what I already use for the same code on a Raspberry Pi). I enabled SPI0 and have devices spidev1.0 and spidev1.1 (for whatever reason, on the latest debian, SPI0 is spidev1.* instead of spidev0.*).
When I send data to the SPI device with normal file access mode - open("/dev/spidev1.0", "wb") - it works fine. But when I use py-spidev like this:

spi = spidev.SpiDev()
spi.open(1,0)
spi.xfer2(buffer)

It sends the first data packet and then never another one. It's not hanging or anything as xfer2 is returning just fine. But the later data never makes it to the strip.

Any ideas?

xfer2 glitch on cs.

Hi,

I am using a Pi 3 version 8 (jessie), and py-spidev (HEAD) (Merge: 511db0d 11adf8c)

When I execute:

resp = spi.xfer2([0xD8, 0x00, 0x00, 0x00])

I see a glitch on CS during the transfer.

Thanks,
Edward

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.