I’m trying to develop a routine for the transfer via serial line with SSI protocol of a 25 bit long word
In essence, the Wifi Kit 32 card simulates an encoder with an SSI interface
By connecting the “SSI card/Encoder” to the PLC, equipped with a specific standard SSI module, I expect to be able to correctly read from the PLC the value present inside the electronic card
The transmission from the electronic card to the PLC seems to work, but sometimes the data read seems totally incorrect
Looking at the electrical signals I see that the data line, driven by an output pin of the kit 32 wifi card, seems to be very imprecise compared to the clock signal edges
In essence, there seems to be an important tolerance between the moment of the falling edge of the clock signal, which must start the interrupt service routine, and the moment that the data line is activated
And this tolerance means that for every few hundred correct readings there is one wrong one
I attach the code I am using in the Arduino IDE environment
What could cause the lack of precision of the signal on the DATA line compared to the CLOCK signal?
#include <Arduino.h>
#include “esp_timer.h”
#include <Wire.h>
#include <WiFi.h>
#include <BluetoothSerial.h>
#define pin_CLOCK 26
#define pin_DATA 47
volatile unsigned int verso = 0;
volatile unsigned long conteggio=8000000;
volatile int numero_bit_inviati = 0;
volatile unsigned long conteggio_congelato_per_invio_a_plc = 0;
esp_timer_handle_t timer_durata_lettura_ssi;
void IRAM_ATTR pin_CLOCK_isr_falling() {
if (numero_bit_inviati == 0) {
digitalWrite(pin_CLOCK_sync_all_tx, HIGH);
esp_timer_stop(timer_durata_lettura_ssi);
esp_timer_start_once(timer_durata_lettura_ssi, 300);
numero_bit_inviati = 25;
conteggio_congelato_per_invio_a_plc = 6710886 ^ (6710886 >> 1);
} else {
numero_bit_inviati = numero_bit_inviati - 1;
}
digitalWrite(pin_DATA, (conteggio_congelato_per_invio_a_plc >> (numero_bit_inviati-2)) & 0x01);
}
void IRAM_ATTR onTimerDurataLetturaSsi(void* arg) {
numero_bit_inviati = 0;
digitalWrite(pin_DATA, HIGH);
digitalWrite(pin_CLOCK_sync_all_tx, LOW);
}
void setup() {
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
btStop();
pinMode(pin_CLOCK, INPUT_PULLUP);
pinMode(pin_DATA, OUTPUT); digitalWrite(pin_DATA, HIGH);
attachInterrupt(digitalPinToInterrupt(pin_CLOCK), pin_CLOCK_isr_falling, FALLING);
const esp_timer_create_args_t timer_args_ssi = {.callback = &onTimerDurataLetturaSsi, .arg = NULL, .name = “timer_durata_lettura_ssi”};
esp_timer_create(&timer_args_ssi, &timer_durata_lettura_ssi);
}
void loop() {
}