2020-07-12 10:52 PM
I'm using stm32 MCU to interface with mcp4821 D A C . The MCU's spi data size is set to 8 bit mode.The D A C has a 16 bit register and (Starting from 0) bit 12 to 15 are configuration bits and the remaining bits are data bits . My problem is ...how should I enter the full scale value by using 8 bit mode spi and how should I separate the data and store it in the first 8 bit register and the other in bit 9 to 12 . I'm new to MCUs and I'm just getting started with programming ... so could anyone please help me with this problem.
2020-07-13 03:20 AM
As the DAC a use a 16 bits register you should use a 16 bits word (uint16_t).
Put the DAC value in the lower bits and the command in the upper bits.
Then send the high byte then the low byte.
Something like this pseudo code:
uint16_t word ;
word = 0x800u ; // The dac value, mid range
word |= 0x3000u ; // Add the command bits
spiCs (0) ; // Set SPI CS low
spiSendByte (word >> 8) ; // Send high byte
spiSendByte (word & 0x00FFu) ; // Send low byte
spiCs (1) ; // Set SPI CS high
2020-07-13 04:39 AM
Which STM32, the range is quite extensive, with assorted functionality.
Perhaps as a pair of 6-bit transactions?
2020-07-13 05:37 AM
maybe read 16 bit modifyand write. this way you know what is happening.