SPI transfer blocked by other functions


my name is chris and i´m working on a temperature regulation. the regulation works fine. the spi communication also works. i want to send the value calculated by the regulation to an extern dac via SPI.

when i calculated the value i return it and handle it to the dac transmitter function, but nothing happens. do the calculations somehow block the transfer?

here my code:

void MyClass::loop() { float z = adc.adcNtc(); // function reads adc value and calculates temperature int t = (int(z))*10; // integer necessary for regulation

int reg = regelung.Ntc(t); // calculate regulation value (works for itself)

dac.setDac(reg,3); // function sends regulationvalue to dac (works for itself)


i can send values to the dac but when i add the calculations it does not work anymore.

i hope you can help me:)

best greetings


Hi, welcome to the forum.

I'm not sure where it stops and which dac library you use. Could you add Serial.println() messages to print the variables like "z", "t" and "reg" to the serial monitor.

Is this Java ? int t = (int(z))*10; In the 'c' or 'c++' language you can cast it to an integer : int t = (int) z * 10;

The DAC.h is a selfwritten class.i use atmel studio.
I’ve written all the values to the display.every variable contains a correct value.
reg is an integer value(value~100-500) .

The cast of int was a typing mistake;)

I’ll post the dac-class at the weekend.

Thanks already!

void DAC::setDac(int value, int channel){ pinMode (chipselect,OUTPUT); digitalWrite(chipselect,HIGH); byte dacRegisterC = 0b10100000;//DAC C byte dacRegisterA = 0b00100000;//DAC A byte dacRegisterB = 0b01100000;//DAC B byte dacRegister; switch (channel) { case 1: dacRegister = dacRegisterA; break; case 2: dacRegister = dacRegisterB; break; case 3: dacRegister = dacRegisterC; break;

} int secondaryBitMask = 0b0000000011111111; byte dacPrimaryByte = value >> 8 | dacRegister; byte dacSecondarybyte = value & secondaryBitMask; noInterrupts(); digitalWrite(chipselect,LOW); SPI.transfer(dacPrimaryByte); SPI.transfer(dacSecondarybyte); digitalWrite(chipselect,HIGH); interrupts();


This is the dacset-function. the dacregister and the upper 8 bits of the 16bit value form the primary bit. the lower 8 bits are the secondary bit.

i hope you can help:=)