Thanks for your reply, Paul!
Think i've already all that what you wrote.
I have just shortened my code with only the basic things.
Doesn't work at all. SPI will only read once at startup. Also if I call the modbys within the "delay".
#include <SimpleModbusSlave.h>
#include <SPI.h>
enum
{
WMOD0_TEMP_EXTR,
HOLDING_REGS_SIZE
};
unsigned int holdingRegs[HOLDING_REGS_SIZE]; // function 3 and 16 register array
unsigned long prevMillis = 0; // will store last time LED was updated
int CSEXTR= 9; // D09: Chipselect MAX6675 Extruder
const long chktemp = 100;
/*
============
= I N I T =
============
*/
void setup() {
// Pins deklarieren
pinMode(CSEXTR, OUTPUT); // CS-Pin Extruder als Output
digitalWrite(CSEXTR, HIGH); // CS-Pin Extruder auf High
// Init Modbus
modbus_configure(&Serial, 9600, SERIAL_8N2, 1, 2, HOLDING_REGS_SIZE, holdingRegs);
modbus_update_comms(9600, SERIAL_8N2, 1);
// Init SPI
SPI.setClockDivider(SPI_CLOCK_DIV2); // wären 8 MHz SPI Takt
SPI.setDataMode(SPI_MODE0); // DataMode 0
SPI.begin();
}
/*
============
= M A I N =
============
*/
void loop() {
modbus_update();
unsigned long actMillis = millis();
if (actMillis - prevMillis >= chktemp) {
prevMillis = actMillis;
digitalWrite(CSEXTR, LOW);
delayMicroseconds(0); // zusätzliche Wartezeit, 100ns erforderlich
uint16_t reading = SPI.transfer16(0);
digitalWrite(CSEXTR, HIGH);
reading = (reading >>3)*25; // the reading is in bits 14..03, get rid of bit 2,1,0
holdingRegs[WMOD0_TEMP_EXTR]=reading; // READ MAX6675 1
}
}
Maybe more ideas?