So in total i have to send 2 bytes for the first wordb, 2 more bytes for the worb again and then 2 more bytes for wordA, this should initialize the chip.
Yes, I believe that should do it, though haven't studied the datasheet in any depth as I'm presently working on an urgent consumer project.
Then everytime i need to change the frequency value i will only need to send wordA.
It outwardly looks that way, though if you split the processing of WordA and WordB to separate macros, this would enable you to separately focus on each to ensure your data's correct, then simply call one or both as occasion demands. I would personally have a single macro updating/reaffirming both registers on each occasion, as this will simplify your code and avoid having to worry about whether the shift-register was in sync or needed a reset during normal operation.
Do i have to reset the loopcount to 8 everytime i exit the loop right?
I would highly advise resetting LoopCount immediately
before you started the loop. This would avoid the potential for LoopCount being altered in any way elsewhere in your program, though normally because LoopCount is (or could be) shared with different program loops so would (should) usually be set immediately before each loop anyway. In your case though, I would create a loop to process an entire 16-bit word. Datasheet Fig.2 suggests least-significant bit first, so simply...
LoopCount = 0 (loop starting value)
Data_Word = the 16 data bits to send
Compare_Word (a 16-bit variable used for loop word compare, where only a single bit in Compare_Word is set high in each case)
SendBit (Boolean)
The loop...
Compare_Word = 1 << LoopCount ...makes Compare_Word a solitary bit value that represents the data bit 'value' that you're presently interested in.
SendBit = (Data_Word AND Compare_Word) >> LoopCount ...Compares the two bit values and shifts (divides) the representative bit value back down so that it cannot be greater than a boolean. For example, if you were comparing a bit value of (say) '32', you must first divide 32 by 32 (e.g. >> 5) to get a maximum value of 1 before assigning to the boolean SendBit. Incidentally, using bit-shift to divide in this way is preferable to using a mathematical divide function, such as when X >> 0 = X, whereas X / 0 would cause a 'divide by zero' error.
Send the bit ...I would suggest creating a macro that specifically handles data and clock timings.
LoopCount = LoopCount + 1 ...This will represent the next bit
value to be set to Compare_Word for AND'ing with the Data_Word (only the single bit set high in Compare_Word, will be taken into account).
If LoopCount > 15 then exit loop
The BitToSend variable has to be a boolean?
In practice it doesn't
have to be, though a Boolean is easier to deal with and better for debug as it relates to just the bit being sent and can never be anything more.
To send the bit it has to be sent out followed immediately by the clock pin and then back to 0 followed by a delay and then to the next bit correct?
Yes, though you must first set the data, allow a small propagation delay, then shift the clock pin high then delay then low, then a further propagation delay before changing the data pin, and so on. Advisedly, a minimum delay between any change on any line. As communication speed is not of the essence for scoping and test and debug, I would start off with a slow data rate of 10kHz for bags of margin initially, with timings between edges as follows:
Set DLEN + 300us
then
Set Data + Wait 300us + Clock High + Wait 300us + Clock Low + 300us ...and repeat for each bit sent.
Set the delay in us to a variable, then you can simply increase the speed later if desired, once you've established that the data is correct and valid.
All the best,
Brendan