It seems to transfer with no errors, but nothing happens.
If I run the code in python then everything works. I can toggle the relay on and off with the following code.
import piplates.RELAYplate as RELAY
import time
RELAY.relayTOGGLE(0,1)
Do I need to open the spi port? Is there something more that I need to do?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your code looks good. I expect, that you are missing some init code. Did you already try "strace" on your python script?
I would either try strace or a python debugger to get a better understanding of the python code.
In CODESYS you can't do much wrong. Except that you might have the wrong device or frequency configured in the SPI master of your project.
Especially the frequency can be important, as on some raspbian versions, the highest possible frequency was not limited correctly. Therefore you need to configure it in the SPI master device in your CODESYS project. (Took me some hours once ;) )
But you don't need to open anything. This is done by the SPI master already.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I figured out the problem with communicating over the SPI bus.
I though this line of code in Python [spi.open(0,1) ] meant open port 0 in mode 1. I found out that this actually means open port 0, device 1. In the SPI master device I needed to replace the value in the SPI Port parameter from '/dev/spidev0.0' with '/dev/spidev0.1'. Once I did this everything started working. I am moving on to complete the driver.
Thanks for your help, confirming the code told me to look in a new direction.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for confirming the code. Knowing the code is good forced me to look in a new direction. The python line of code [spi.open(0,1)] was the area I needed to focus on. I read some website that said spi.open(0,1) meant open port 0 in mode 1. Then I found out it meant open port 0 using device 1. I changed the settings in the SPI master on the in the device parameters. I put as spidev0.1 instead of spidev0.0. Then everything started to work.
Thanks for the help!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
more posts ...
Suggested Edit:
SPI Transfer
You might have noticed the few lines above:
Thanks for the report!
I am having trouble writing to the SPI bus.
I have a python script I am trying to translate to codesys.
SPI Master settings in codesys:
Max Hz 500000
bits per word is 8
port mode is 1
It seems to transfer with no errors, but nothing happens.
If I run the code in python then everything works. I can toggle the relay on and off with the following code.
import piplates.RELAYplate as RELAY
import time
RELAY.relayTOGGLE(0,1)
Do I need to open the spi port? Is there something more that I need to do?
Your code looks good. I expect, that you are missing some init code. Did you already try "strace" on your python script?
I would either try strace or a python debugger to get a better understanding of the python code.
In CODESYS you can't do much wrong. Except that you might have the wrong device or frequency configured in the SPI master of your project.
Especially the frequency can be important, as on some raspbian versions, the highest possible frequency was not limited correctly. Therefore you need to configure it in the SPI master device in your CODESYS project. (Took me some hours once ;) )
But you don't need to open anything. This is done by the SPI master already.
I figured out the problem with communicating over the SPI bus.
I though this line of code in Python [spi.open(0,1) ] meant open port 0 in mode 1. I found out that this actually means open port 0, device 1. In the SPI master device I needed to replace the value in the SPI Port parameter from '/dev/spidev0.0' with '/dev/spidev0.1'. Once I did this everything started working. I am moving on to complete the driver.
Thanks for your help, confirming the code told me to look in a new direction.
Thanks for confirming the code. Knowing the code is good forced me to look in a new direction. The python line of code [spi.open(0,1)] was the area I needed to focus on. I read some website that said spi.open(0,1) meant open port 0 in mode 1. Then I found out it meant open port 0 using device 1. I changed the settings in the SPI master on the in the device parameters. I put as spidev0.1 instead of spidev0.0. Then everything started to work.
Thanks for the help!