Markus_L811
Well-known member
I worked on an Onewire-Slave lib first thinks worked good but after I try to move the attachinterrupt-routine in the library it goes strange.
Here a the exiting parts:
I try to move the double definition of the Slave Pin and the Interrupt Pin inside the lib to make it easy to set it up and make some define's to sort out for some Arduinoboards and ARM Boards (T3 Due as far) I attached 2 Sketches ..._fulllib is the one under construction the other is the "normal" one with seperate Pin discription for the lib and in sketch function.
The constution is:
in the h for wrapping out of the static trap of the attachinterrupt-routine
(an good friend helped me with that)
move this stuff from the sketch
in the cpp for the MasterResetPulseDetection.
And now to the problem:
In the old version all works fine just, but in new one it seems there is an issue with this functions if some of this is called
#define DIRECT_READ(base, mask) (*((base)+512))
#define DIRECT_MODE_INPUT(base, mask) (*((base)+640) = 0)
#define DIRECT_MODE_OUTPUT(base, mask) (*((base)+640) = 1)
#define DIRECT_WRITE_LOW(base, mask) (*((base)+256) = 1)
#define DIRECT_WRITE_HIGH(base, mask) (*((base)+128) = 1)
My T3 get broken and the T3 stopped working. I don't think it's on the functions above I reckon it's more a Problem how they called inside the wrapped interrupt function, but I have no answer.
I don't know why it don't work in this way, can someone help me please.
Here a the exiting parts:
I try to move the double definition of the Slave Pin and the Interrupt Pin inside the lib to make it easy to set it up and make some define's to sort out for some Arduinoboards and ARM Boards (T3 Due as far) I attached 2 Sketches ..._fulllib is the one under construction the other is the "normal" one with seperate Pin discription for the lib and in sketch function.
The constution is:
in the h for wrapping out of the static trap of the attachinterrupt-routine
(an good friend helped me with that)
Code:
class OneWireSlave {
...
public:
...
void init2(unsigned char rom[8], uint8_t pin);
void MasterResetPulseDetection();
static void ISRPIN();
...
static OneWireSlave* static_OWS_instance;
#endif
move this stuff from the sketch
Code:
//Interrupt
volatile long previousmicros = 0;
volatile long old_previousmicros = 0;
volatile long difference = 0;
void setup() {
...
attachInterrupt(dsslaveassignedint, DS18B20, CHANGE);
...
}
void DS18B20() {
old_previousmicros = previousmicros;
previousmicros = micros();
difference = previousmicros - old_previousmicros;
if (difference >= lowmark && difference <= highmark) {
ds.waitForRequestInterrupt(false);
}
}
Code:
...
void OneWireSlave::ISRPIN() {
(*static_OWS_instance).MasterResetPulseDetection();
}
void OneWireSlave::MasterResetPulseDetection() {
old_previous = previous;
previous = micros();
diff = previous - old_previous;
if (diff >= lowmark && diff <= highmark) {
waitForRequestInterrupt(false);
}
}
...
void OneWireSlave::init2(unsigned char rom[8], uint8_t pin) {
for (int i=0; i<7; i++)
this->rom[i] = rom[i];
this->rom[7] = crc8(this->rom, 7);
attachInterrupt(pin, &ISRPIN, CHANGE);
}
And now to the problem:
In the old version all works fine just, but in new one it seems there is an issue with this functions if some of this is called
#define DIRECT_READ(base, mask) (*((base)+512))
#define DIRECT_MODE_INPUT(base, mask) (*((base)+640) = 0)
#define DIRECT_MODE_OUTPUT(base, mask) (*((base)+640) = 1)
#define DIRECT_WRITE_LOW(base, mask) (*((base)+256) = 1)
#define DIRECT_WRITE_HIGH(base, mask) (*((base)+128) = 1)
My T3 get broken and the T3 stopped working. I don't think it's on the functions above I reckon it's more a Problem how they called inside the wrapped interrupt function, but I have no answer.
I don't know why it don't work in this way, can someone help me please.
Attachments
Last edited: