Hi everybody
I am controlling a BLACF30-C142 linear actuator (https://en.inspire-robots.com/product/blacf30-c142-series) from my Teensy 4.1 (I use Teensyduino 1.8.13 linuxaarch64). Therefore, I have connected my Teensy's RX3 and TX3 pins to a UART-RS485 converter and the actuator's A+ and B- ports to the same converter. Afterwards, I chose my Teensy's pin 18 to be the "ENABLE" pin (HIGH when the serial line is in writing mode and LOW otherwise). The baud rate is set to 115200 bits/second.
Since I want to send an array of values to the linear actuator, I wrote the following code as per the linear actuator's protocol:
The code above works well. However, I would like to know if there is a way to avoid calling the
instruction, please. I would like the
instruction to be called as soon as the last bit in the Serial3 channel's buffer has been sent out. I am considering using the Teensyduino's interrupts (i.e.,
), but I do not if it is the right strategy.
If I have to go with interrupts, how could I activate the interrupt when Serial3 channel's buffer is empty?
I am controlling a BLACF30-C142 linear actuator (https://en.inspire-robots.com/product/blacf30-c142-series) from my Teensy 4.1 (I use Teensyduino 1.8.13 linuxaarch64). Therefore, I have connected my Teensy's RX3 and TX3 pins to a UART-RS485 converter and the actuator's A+ and B- ports to the same converter. Afterwards, I chose my Teensy's pin 18 to be the "ENABLE" pin (HIGH when the serial line is in writing mode and LOW otherwise). The baud rate is set to 115200 bits/second.
Since I want to send an array of values to the linear actuator, I wrote the following code as per the linear actuator's protocol:
C++:
void setup() {
Serial3.begin(115200);// Baud rate set to 115200
pinMode(18,OUTPUT);// Enable pin is OUTPUT
digitalWrite(18,LOW);// Enable pin is LOW
}
void loop() {
// Construct a packet to send to the linear actuator
uint8_t TX_Array[40] = {0};
TX_Array[0] = 0x55;
TX_Array[1] = 0xAA;
TX_Array[2] = 0x03;// Length of the data frame
TX_Array[3] = 0x01;// Motor ID
TX_Array[4] = 0x30;// Instruction type
TX_Array[5] = 0x00;// Register address
TX_Array[6] = 0x00;
TX_Array[7] = 0x00;// Checksum
const int Tx_Len = 3;// Length of the data
// Compute the checksum
unsigned int i = 0;
int size_cnt = 0;
uint8_t check_sum = 0;
for (i=2;i<(Tx_Len + 4);i++)// The checksum does not consider the first two bytes. The last byte stores the checksum
{
check_sum = check_sum + TX_Array[i];
}
TX_Array[Tx_Len + 4] = check_sum & 0xFF;
size_cnt = Tx_Len + 5;// The total size of the packet
// Send the packet to the linear actuator via Serial3
digitalWrite(18,HIGH); // Serial3 is in writing mode
Serial3.write(TX_Array,size_cnt);
delayMicroseconds(1150);
digitalWriteFast(18,LOW);// Serial3 is in listening mode
delayMicroseconds(1000);
}
The code above works well. However, I would like to know if there is a way to avoid calling the
C++:
delayMicroseconds(1150);
C++:
digitalWriteFast(18,LOW)
C++:
attachInterruptVector()
If I have to go with interrupts, how could I activate the interrupt when Serial3 channel's buffer is empty?
Last edited: