Need to slow down SPI encoder clock, how?

I have odrive S1 and I need to read SPI encoder supporting AMS-SPI but spi clock is too fast (625ns period). Is there a way I can drop this to half of this? or 1/4 ?

You can try setting the SPI encoder baudrate. Note that at too low values, the ODrive may not be able to read data in time for the controller to run, which would lead to an error.

1 Like

Thanks. I need to go very low, just to see that proper data is being sent by me, when new proper pcb arrives we’ll up the clock :slight_smile:

I replaced the slave MCU and now communication looks ok on logic analyzer but I still do not see anything on the odrive :frowning:

sending some static position in a loop

position = 123;

position = (ams_parity(position) << 15) | position;
pTxData[0]=position >> 8;
pTxData[1]=position & 0xFF;
HAL_SPI_TransmitReceive(&hspi2, pTxData, pRxData, 2, 1000);

LA shows everything ok, nothing between odrive and mcu except direct short wires, slow and steady and … odrive is reading zero :frowning:

In [254]: odrv0.spi_encoder0
Out[254]:
config:
  baudrate: 664379 (uint32)
  delay: 0.0 (float)
  max_error_rate: 0.004999999888241291 (float)
  mode: 2 (uint8)
  ncs_gpio: 12 (uint8)
get_field_strength(obj: object_ref) -> field_strength: float
inject_errors: False (bool)
n_errors: 16612385 (uint32)
raw: 0.0 (float)
status: 1 (uint8)

same if I’m sending 0x0030 or 0x0031 or 0x8030 or 0x8020 or 0x8DFC or … n_errors goes up and raw is non stop 0.0 :frowning: … now sure what to send to odrive :frowning: now when I have communication running

I try CUI too:

In [316]: odrv0.spi_encoder0
Out[316]: 
config:
  baudrate: 1300000 (uint32)
  delay: 0.0 (float)
  max_error_rate: 0.004999999888241291 (float)
  mode: 3 (uint8)
  ncs_gpio: 12 (uint8)
get_field_strength(obj: object_ref) -> field_strength: float
inject_errors: False (bool)
n_errors: 131607 (uint32)
raw: 0.0 (float)
status: 1 (uint8)

sending 0x61AB (example from datasheet for cui) on the first edge as CUI datasheet states (AMS was on trailing edge)

	  pTxData[0]=0x61; //position >> 8;
	  pTxData[1]=0xAB; //position & 0xFF;
	  HAL_SPI_TransmitReceive(&hspi2, pTxData, pRxData, 2, 1000);

LA shows good data…


(first decoder is for 0,1 or trailing edge and second decoder is for 0,0 or leading edge)

hm, looks like firmware update to 0.6.8 solved the problem