I am currently using SPI 2 on stm32f407 disc board. I have defined the Stm32 pins in the below given manner.
my CS pin is " PB14" which i have definedPB10 ------> SPI2_SCK
PC2 ------> SPI2_MISO
PC3 ------> SPI2_MOSI
cs_pin = Pin('PB14', Pin.OUT_PP, Pin.PULL_NONE)
From my understanding of SPI used for serial communication, we have to take CS pin low/high to read or write any data.
Now to perform a write a single byte, I have to toggle CS pin from high to low state, than write the data and than toggle the CS pin state to higher state. Similar procedure goes with Read cycle.
But problem here is whenever i try to receive data, it gives me "0xff " in data buffer.
Code: Select all
from pyb import SPI , Pin
#Initialising Chip select pin
cs_pin = Pin('PB14', Pin.OUT_PP, Pin.PULL_NONE)
#Initialising SPI
spi = SPI(2,SPI.MASTER)
#Defined Register
EEP_WRITE = 0x02 # Write bit of IR
EEP_READ = 0x03 # Read bit of IR
EEP_WREN = 0x06 # Write Enable Latch
EEP_WRDI = 0x04 # Write Disable Latch
EEP_RDSR = 0x05 # Read Status Reg
EEP_WRSR = 0x01 # Write Status Reg
# @brief Drive CS output pin to low/high level to select slave device
# * via /CS pin state
# * @param state state State of CS output pin that will be driven:
# * @arg 0 (DISABLE): Drive CS pin to low level
# * @arg 1 (ENABLE) : Drive CS pin to high level
# * @return None
DISABLE = 0
ENABLE = 1
def SPI2_CS_Force (state):
if (state):
cs_pin.value(1)
else:
cs_pin.value(0)
# * @brief This Function configures and Initializes SPI2
# * @retval None
def ASK25_SPI2_Init( ):
spi = SPI(2,SPI.MASTER, prescaler = 128, polarity = 0, phase = 0, bits = 8, firstbit = SPI.MSB , ti = False, crc = None)
# @brief Get the status about locked or unlocked memory blocks.
# @return status register byte
def ASK25_25AA160A_Read_Status_Reg ():
reg = bytearray(35)
status = 0
inst = bytearray(35)
for x in range (35):
inst[x] = x
inst[0] = EEP_RDSR
cs_pin.value(0)
spi.send(inst, timeout = 500)
cs_pin.value(1)
pyb.delay(10)
cs_pin.value(0)
status = spi.recv(reg, timeout = 500)
cs_pin.value(1)
print(reg)
def main():
while True:
ASK25_25AA160A_Read_Status_Reg()
pyb.delay(100)
main()
Have anyone faced the same issue ?