2019-10-19 06:53 AM
hi I should read the value of the angle of the encoder as5048a via spi, the register has address 0x3fff, a 14-bit register, I tried in several but I failed, can you help me? I use a f401 !! thanks
2019-10-19 10:11 AM
What do you mean by "tried in several but I failed"? Show us what did you do, what was the expected behaviour and what was the observed one.
JW
2019-10-19 11:31 AM
i have tried :
HAL_SPI_Transmit(&hspi2,0x3fff,1,1000);
////// HAL_SPI_Receive(&hspi2,data,2,1000);
--------------------------------------------------------------
HAL_SPI_TransmitReceive(&hspi2,0x3fff,data,4,255);
data[0] = data[0] << 8;
// result = data[1]| data[0];
-------------------------------------------------------------
digitalWrite(SS, LOW);
//Reading 8 bit frame (the first half of 16-bit SPI transfer)
result1 = SPI.transfer(0xfEEE);
result1 &= 0b00111111;
);
result1 = result1 << 8;
// getting last 8 bits (the last half of 16-bit SPI transfer)
result2 = SPI.transfer(0xfEE);
// merging
result = result1 | result2;
with arduino no problem goes very well!
but with stm32 no,i don't undertand!
2019-10-19 11:32 AM
0X3FF sorry!
2019-10-19 11:37 AM
with arduino I receive the two bytes correctly and if I move the encoder I read the data, but with stm it always gives me the same number
2019-10-20 10:29 AM
word command = 0b0100000000000000;
command = command | 0X3FFF;
command |= ((word)spiCalcEvenParity(command)<<1;
byte right_byte = command & 0xFF;
byte left_byte = ( command >> 8 ) & 0xFF; SPI -
SPI.beginTransaction(settings);
digitalWrite(_cs, LOW);
SPI.transfer(left_byte);
SPI.transfer(right_byte);
digitalWrite(cs,HIGH)
digitalWrite(_cs, LOW);
left_byte = SPI.transfer(0x00);
right_byte = SPI.transfer(0x00);
digitalWrite(_cs, HIGH);
SPI.endTransaction();
return (( ( left_byte & 0xFF ) << 8 ) | ( right_byte & 0xFF )) & ~0xC000;}
2019-10-20 10:30 AM
i have founded the function with arduino for as5048a but i can't translate it!!!!
2019-10-20 09:36 PM
From the data sheet: "The 16 bit SPI Interface..." -> the size is always 2 bytes (or 16 bits).
You send two half words: The READ and the NOP (all-zero). During NOP the chip transmits the data.
You also need to calculate the parity. If the parity is wrong, I think the chip ignores the command.
The READ-command is 0x3FFF | 1 << 14 (read) | 1 << 15 (parity) = 0xFFFF