Estoy intentando crear un controlador para as5048a (spi) en STM32f405rg
Este codificador magnético se supone que tiene 14 bits de resolución:
yelpaquetedelecturamuestraquelos2MSBsonmarcasdeparidadyerror
Asíquelosestoyocultando:
uint8_trMSB=0,rLSB=0;AS5048A_cs(&self->cs,0u);rMSB=SPI_read_byte(self->spi);rLSB=SPI_read_byte(self->spi);AS5048A_cs(&self->cs,1u);*buf=(((rMSB<<8)|rLSB)&~0xC000);
Perocuandoleobuf,soloobtengovaloresde8192(0x2000)a16384(0x4000).Talvezalguienyahayaenfrentadoesteproblemaypuedaexplicarloqueestoyhaciendomal.EDITAR:
{
uint16_t command = 0b0100000000000000; // PAR=0 R/W=R
command |= reg;
command |=((uint16_t)spiCalcEvenParity(command)<<15);
// send register address to be read
uint8_t MSB = (command>>8) | 0xFF; // shift the upper 8 bits down
uint8_t LSB = command | 0xFF; // mask upper 8 bits
AS5048A_cs(&self->cs, 0u);
SPI_write_byte(self->spi, MSB);
SPI_write_byte(self->spi, LSB);
AS5048A_cs(&self->cs, 1u);
/*
second command should be 0x0000 (nop) or clear flag (0x0001)
but when sending the second command, there's no angle returned.
thus by commenting this it gives me an angle from 0x2000 to 0x3FFF
AS5048A_cs(&self->cs, 0u);
SPI_write_byte(self->spi, 0x00);
SPI_write_byte(self->spi, 0x01);
AS5048A_cs(&self->cs, 1u);
*/
uint8_t rMSB=0,rLSB=0;
// read data
AS5048A_cs(&self->cs, 0u);
rMSB = SPI_read_byte(self->spi);
rLSB = SPI_read_byte(self->spi);
AS5048A_cs(&self->cs, 1u);
*buf = ((( ( rMSB & 0xFF ) << 8 ) | ( rLSB & 0xFF )) & ~0xC000);