CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Pi3 B+ with Stretch - MCP3008 SPI Not working
https://forum.codesys.com/viewtopic.php?f=21&t=9265
Page 1 of 1

Author:  Anerdgy [ Tue Oct 30, 2018 9:10 am ]
Post subject:  Pi3 B+ with Stretch - MCP3008 SPI Not working

Hi

am trying to get the MCP3008 to work with the Pi3 B+ using teh MCP3008 sample project.

Unfortunately not receiving any readings. The hardware is defintely OK as with a python script I can read the values normally.

I am using Hardware SPI.

SPI master and devices running.

Thanks in advance

Peter

Author:  Edwin Schwellinger [ Tue Oct 30, 2018 9:14 am ]
Post subject:  Re: Pi3 B+ with Stretch - MCP3008 SPI Not working

Hi,
since Stretch fullspeed SPI does not work - so you need to reduce it here.
BR
Edwin

Author:  Anerdgy [ Tue Oct 30, 2018 10:30 am ]
Post subject:  Re: Pi3 B+ with Stretch - MCP3008 SPI Not working

Many thanks. That solved it. I'm curious as to why the hardware code using the Adafruit python code worked as I had not changed the SPI speed.

Secondly, how do I change it to use the second SPI hardware pins? ie using a differnet GPIO as chip select, BCM19 pin 35 MISO, BCM20 pin 38 MOSI and BCM21 pin 40 SCLK as I will now purchase a canberry dual board to mount and it is already using the original SPI pins as well as CE0 and CE1. Maybe I could just use a different GPIO for chip select , but if it affects the timing, maybe easier to move all the MCP3008 work onto the second SPI pins.

https://www.industrialberry.com/canberrydual-iso-v2-1/

Many thanks

Peter

Author:  Anerdgy [ Thu Nov 01, 2018 12:09 pm ]
Post subject:  Re: Pi3 B+ with Stretch - MCP3008 SPI Not working

Through trial and error it seems that the max SPI clock speed is 7.8Mhz. If I go higher eg 15.6Mhz, I get a reduced scale and it no longer reads the values correctly.

Author:  Anerdgy [ Thu Nov 01, 2018 2:55 pm ]
Post subject:  Re: Pi3 B+ with Stretch - MCP3008 SPI Not working

To answer my own question....

Enable SPI1 on the raspberry pi in the config.txt

Then add another device under the SPI and change the SPI port and MaxSpeed (due to stretch issue), move the MCP3008 into it.

And all works. You can change the CS pin as well on the pi.

I found this link useful . https://terminal28.blogspot.com/2016/05/enabling-spi1-on-raspberry-pi-bzero23.html

Author:  Edwin Schwellinger [ Fri Nov 02, 2018 7:26 am ]
Post subject:  Re: Pi3 B+ with Stretch - MCP3008 SPI Not working

Hi,
thanks for this helpful information for the community, well appreciated.

BR
Edwin

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/