lthiery / SPI-Py

Hardware SPI as a C Extension for Python
286 stars 150 forks source link

Sending 256 bytes or greater hangs SPI-Py #6

Closed blark closed 10 years ago

blark commented 10 years ago

I am using the plugin to play with a SPI SRAM (512kbit). For now I am simply filling it up and then reading back to make sure that the memory (and SPI) works properly.

The SRAM has sequential write mode so I can write many bytes at once, like so:

DATA = (0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, 0xF0, 0x0D) * 16

spi.transfer((0x02, 0,0) + (DATA))

This method works great, as you can see this is transmitting 128bytes. As soon as I double it the program just hangs. Anything below 16 bytes works fine. I've read that that SPI chip is capable of sending up to 4096 bytes at once, it would be great if I could take advantage of that so I can read/write faster.

Any ideas of what might be causing this? If you need any debug information please let me know.

blark commented 10 years ago

Found the issue. The loop is using an uint8_t when it should be a uint16_t:

 uint8_t i=0;

        while(i < tupleSize)
        {
                tempItem = PyTuple_GetItem(transferTuple, i);                //
                if(!PyInt_Check(tempItem))
                {
                        pabort("non-integer contained in tuple\n");
                }
                tx[i] = (uint8_t)PyInt_AsSsize_t(tempItem);

                i++;

        }

Changing uint8_t to uint16_t and recompiling fixes the bug, I can now happily write >255 (tested up to 1Kbyte and it works great)

lthiery commented 10 years ago

Hi Blark

Thanks for catching this AND fixing it! I don't have time to dig and verify the fix but from what I read here it looks like you did an awesome job. I'll merge it for now with that assumption ;)

Best, Louis

--Louis

blark commented 10 years ago

Heh, no problem. Thanks for the great work on the plugin.

On Thu, Oct 31, 2013 at 4:08 PM, Louis Thiery notifications@github.comwrote:

Closed #6 https://github.com/lthiery/SPI-Py/issues/6.

— Reply to this email directly or view it on GitHubhttps://github.com/lthiery/SPI-Py/issues/6 .