Arctic_Eddie
Well-known member
I have a curve tracer project that uses the T4.1, TFT-touch, and the AD9833 board. The library is the ILI9341-t3n. Everything worked OK until the AD9833 was added. Hardware SPI did not work as the board wanted mode 2. Also, neither of the AD9833 libraries would work. The software SPI was tried on various pins but with no success. Close examination of the AD9833.cpp file reveals that it did not actually use SPI but a straight forward bit-bang technique. There was no attempt to create any kind of timing of output so it ran as fast as possible. That probably worked fine on the Uno and related boards with 16MHz clocks. However, that's not the case with the T4.1 as it's way too fast. The solution was to slow down the output rate by inserting a time delay into the last line of six for{} loops. This essentially makes the rate 1MHz.
At the end of the file, there are two procedures that need an addition, AD9833::writeData(uint16_t data), and AD9833::writeData28(uint16_t LSB, uint16_t MSB). The first has two for{} loops and the second has four. Into each of these six loops, insert as the last line, delayMicroseconds(1); The first one is shown below. Once this is done then the board is compatible with the other objects.
At the end of the file, there are two procedures that need an addition, AD9833::writeData(uint16_t data), and AD9833::writeData28(uint16_t LSB, uint16_t MSB). The first has two for{} loops and the second has four. Into each of these six loops, insert as the last line, delayMicroseconds(1); The first one is shown below. Once this is done then the board is compatible with the other objects.
Code:
// MSBFIRST
for (uint16_t mask = 0x8000; mask; mask >>= 1)
{
uint8_t oldSREG = SREG;
noInterrupts();
if (data & mask) *_dataOutRegister |= outmask1;
else *_dataOutRegister &= outmask2;
*_clockRegister &= cbmask2;
*_clockRegister |= cbmask1;
SREG = oldSREG;
delayMicroseconds(1); // Slow down for T41 ************************
}