Blargh.
If only they sent (
OVL|OVH) and (
OVL) instead, you'd have first bit (MSB) signal overflow, and the rest would form a 23-bit two's complement result. Now, you need to do several bit ops on the MCU to get the correct result.
That was not designed by anyone who has ever written or maintained code that needs to process the results.
Oh and while I am at it, the DR bit is not apparently usable because it is undefined until conversion is complete
So one starts the conversion and waits (osDelay(90)) for the 80ms conversion time (-50 version) and then just reads out the data.
Well that's stupid for sure.
Could you use mode 3 (1,1) instead? After you start the conversion, you keep SCK high, CS low, and wait for the MCP3550 to drive MISO high. Then, you just do a 24-bit transfer to get the 24-bit result, without the useless DR bit.
In mode 0,0, keeping SCK low while waiting for rising edge of MISO, I'd probably get rid of the useless DR bit by temporarily switching SCK to a GPIO, and doing an extra SCK pulse (⊓) by hand (keeping it high for a minimum of 90ns).
My currently preferred microcontroller, Teensy 4, cannot read the MISO pin while it is assigned to the SPI (LPSPI) – there are two separate GPIO subsystems and each includes their own input part (and only one is DMA-capable); no input part is always connected to the pin – so I'd have to fiddle with the MISO pin control anyway. Doing some SCK shenanigans on top of that is no biggie. It's only 90ns plus transitions and pin control setting, fortunately. On the other hand, Teensy 4 supports 25-bit transfers, so I'd just (EDIT: do mode 3 instead, and) extract
OVL|OVH, drop DR, and copy
OVL to bits 22-31 to obtain the 32-bit sign-extended twos complement reading. It might be worth it to use LSB bit order, so these bits would be at the low end –– using the three low bits for a lookup table with eight 32-bit entries, a shift right and shift left to drop the unused bits, an
RBIT (Cortex-M7 instruction) to reverse the bit order in the 32-bit word, and do an OR with the looked-up 32-bit entry to fix-up the value with sign extension and all.
On a 8-bit MCU like AVRs, I'd definitely use SPI mode 3. The MISO pin can be read (
PINB bit 3 on ATmega32u4, my favourite 8-bitter), so I'd probably poll it, or electrically connect to a separate input pin that supports rising edge interrupt.
Errata basically tell you mostly about the state of the battle between marketing and engineering at the vendor, the more embarrassing the errors they will admit to the better that fight is going, but just because something is not in the errata does not mean it works until you have verified the functionality.
Yep; and this is good for hobbyists like myself to consider when reading datasheets and their errata.