I'm in the process of writing a C library for communicating to a DAC60501 using SPI (datasheet:
https://www.ti.com/lit/ds/symlink/dac80501.pdf). I'm writing this in MplabX using the XC16 compiler.
The DAC needs at least 24 falling edges of SCLK (pg 24), so I have used the MCC generated library for a 32 bit transfer on my PIC24FJ256GA406.
The actual 'data' to send consists of 20 bits, itself 4 bits to indicate the register being written to, and 16 bits of 'data' (pg 29).
In my .h file (attached), I have defined values for these registers, as per table 4 on page 28 using #define x y.
In my .c file (attached), I attempt to construct a 32 bit variable to send, by first shifting register data by 16 places (line 42), then OR'ing with the value I wish to output on the DAC (line 43). I then pass this 32 bit value to a function (line 44), where I shift it by 8 bits to move the register and data to the MSB of the 32 bits, and then send using an MCC function (line 11). However, I do not see any output from my DAC.
I've used the debugger (excuse the Nop() on line 10), and have discovered that the register value (DAC_DATA) is not being shifted in the data_out variable on line 42. Is it not possible to use #defines in this way? Or do I need to be more explicit in my declarations?
I now realise that this will affect the init function, but hopefully by learning how I have incorrectly implemented this portion of the code, I will be able to rewrite the init to proper functionality.
The code as attached is a bit messy due to my debugging attempts, but I would also welcome suggestions to improve/standardise my code - I'm still new to programming and very much learning the basics.