Teensy 4.1 Serial Ports and GPIO

bdoan

Well-known member
I am not clear on how Arduino code works with the "shiftout" function.

I need to shift out 12 bits.

should I use the shiftout or just bitbang with other functions?

Code:
void WriteToDAC(void)
{
//#define DAC_CLK     28
//#define DAC_Data    29
//#define VddDAC_Sel  30

byte bitcount;
int  DACvalue;
if (DACbuffer > 4095)         // tens, ones, tenths
   DACbuffer = 0;             // limit to f.s. of DAC 5V   
DACvalue = DACbuffer * 16;   // Move 12 bit to MSB position for 16bit (long)         
output_low(VddDAC_Sel);
for (bitcount=12; bitcount>0;bitcount--)
   {
   shiftOut(DAC_Data,DAC_CLK,MSBFIRST,DACbuffer[bitcount]);  ??????????????
   //Output_High(DAC_CLK);     ??????????????
   //delay(1);                             ??????????????
   //Output_Low(DAC_CLK);      ??????????????
   }
output_high(VddDAC_Sel);
}
 
shiftOut() transmits a byte (8 bits).

Documentation here:

For 12 bits, just write your own loop using digitalWriteFast() and delayNanoseconds() or delayMicroseconds().
 
shiftOut() transmits a byte (8 bits).

Documentation here:

For 12 bits, just write your own loop using digitalWriteFast() and delayNanoseconds() or delayMicroseconds().
Thanks.

Shift and test bit?
Or just AND with a mask to get the bit value?
 
Back
Top