SBUS implementation? #499
Replies: 4 comments 23 replies
-
Oh dear lord...... Yeah that's gonna be fun to port. I see no fundamental barriers, but just a bunch of tedious porting of "configure this peripheral to do this on a '328p" to "configure the corresponding peripheral on a modern AVR to do the same thing, And don't do that godawful stuff with ISR function pointers. Never have ISRs call function pointers. That s a very bad design pattern that WInterrupt started. Just because the Arduino team did something apocalyptically bad becaise it was the only way to make the API they wanted happen, instead of making the API more consistent with what the hardware pushes you to do, doesn't mean we should do the same damned thing even when we don;t need to. |
Beta Was this translation helpful? Give feedback.
-
Hello grandaspanna I think, the Series 0/1/2 are great for SBUS, there have the option to inverted Pins (PORT_INVEN ) for the inverted SBUS-Signal, for need no Serial Bitbanging with Timer or a transistor, and can use the harware-serial :-) I have tested a little with SBUS (old version with no Telemtry), no perfect, no failsave etc., but for first steps, its run: greats Holle |
Beta Was this translation helpful? Give feedback.
-
I search a way to reset the RTC to zero (in the ISR), have anyone a idea ? Or another idea ? (When there is on the Sbus Rx-ISR ~4mS no trigger, the count must be reset to zero. ) [CODE] volatile uint8_t count,timeout,INBYTE[30]; void setup() { Serial1.begin(115200); // Serialdebug nur beim Attiny 1624/3224 (mind. 2xUSART) // RTC as peridic interrupt timer, all ~4mS void loop() {
SERVO_1.writeMicroseconds((Ch[1]>>1)+1000); Serialdebug(); delay(300); //only with Chips witz 2xUART } //Nur beim Attiny 1624/3224 (mind. 2xUSART) ISR(USART0_RXC_vect){ ISR(RTC_PIT_vect){ // RTC Interrupt |
Beta Was this translation helpful? Give feedback.
-
shouldn't 24 pin attiny 2-series parts get the same treatment?
…On Sat, Aug 7, 2021 at 9:05 AM hmeijdam ***@***.***> wrote:
Updated version that will automatically detect during compilation if it is
a 14 or 20 pin part and if there is a second UART on board.
#include <Servo_megaTinyCore.h>
Servo SERVO_1; Servo SERVO_2; Servo SERVO_3; Servo SERVO_4; Servo SERVO_5;
volatile uint8_t count, timeout, INBYTE[30];
uint16_t Ch[16];
void setup() {
#if defined (__AVR_ATtinyx24__) || defined (__AVR_ATtinyx26__) // 2 series parts with 14 or 20 pins
Serial1.begin(115200); // Serialdebug nur beim Attiny 1624/3224 (mind. 2xUSART)
#endif
PORTB.PIN3CTRL |= PORT_INVEN_bm; // Rx Eingangsignale invertieren
USART0.BAUD = 800; // 100.000bps SBUS für 20MHz
USART0.CTRLA |= USART_RXCIE_bm; // RX ISR ON
USART0.CTRLB |= USART_RXEN_bm; // RX aktivieren
SERVO_1.attach(0); SERVO_2.attach(1); SERVO_3.attach(2); SERVO_4.attach(3);
#if defined(__AVR_ATtinyxy4__) // 14 pin parts
SERVO_5.attach(6);
#elif defined(__AVR_ATtinyxy6__) // 20 pin parts
SERVO_5.attach(4);
#endif
// RTC as counter with OVF at ~4mS
while (RTC_STATUS & RTC_PERBUSY_bm) {} // wait until RTC_PER is available for writing
RTC_PER = 128; // Set TOP of timer to approximately 4 ms
RTC_CLKSEL = RTC_CLKSEL_INT32K_gc; /* Internal 32kHz OSC */
RTC_INTCTRL |= RTC_OVF_bm; // activate overflow interrupts
RTC_CTRLA |= RTC_RTCEN_bm; // turn on RTC
}
void loop() {
if (timeout) {
timeout = 0;
count = 0;
for (uint8_t BBit = 0, CBit = 0, i = 0; i < 176; i++, BBit++, CBit++) {
if (INBYTE[i / 8 + 1] & _BV(BBit)) Ch[i / 11 ] |= _BV(CBit); else Ch[i / 11] &= ~_BV(CBit);
if (BBit > 6) BBit = 255;
if (CBit > 9) CBit = 255;
}
Serialdebug(); //only with Chips witz 2xUART
}
SERVO_1.writeMicroseconds((Ch[1] >> 1) + 1000);
SERVO_2.writeMicroseconds((Ch[2] >> 1) + 1000);
SERVO_3.writeMicroseconds((Ch[3] >> 1) + 1000);
SERVO_4.writeMicroseconds((Ch[4] >> 1) + 1000);
SERVO_5.writeMicroseconds((Ch[5] >> 1) + 1000);
}
//Nur beim Attiny 1624/3224 (mind. 2xUSART)
void Serialdebug() { //nur At1624
#if defined (__AVR_ATtinyx24__) || defined (__AVR_ATtinyx26__)
for (uint8_t i = 0; i <= 15; i++) {
Serial1.print((Ch[i] >> 1) + 1000);
Serial1.print("\t");
}
Serial1.println();
#endif
}
ISR(USART0_RXC_vect) {
INBYTE[count] = USART0.RXDATAL;
count++;
while (RTC_STATUS & RTC_CNTBUSY_bm) {} // wait until RTC_CNT is available for writing
RTC_CNT = 0; // clear the RTC counter register
}
ISR(RTC_CNT_vect) { // RTC Interrupt
RTC_INTFLAGS = RTC_OVF_bm; // clear Interrupt Flag
timeout = 1;
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#499 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTXEW56L675H6WLE6BA7TLT3UVS5ANCNFSM5BQEJVJQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
--
____________
Spence Konde
Azzy’S Electronics
New products! Check them out at tindie.com/stores/DrAzzy
GitHub: github.com/SpenceKonde
ATTinyCore <https://github.com/SpenceKonde/ATTinyCore>: Arduino support for
all pre-2016 tinyAVR with >2k flash!
megaTinyCore <https://github.com/SpenceKonde/megaTinyCore>: Arduino support
for all post-2016 tinyAVR parts!
DxCore <https://github.com/SpenceKonde/DxCore>: Arduino support for the AVR
Dx-series parts, the latest and greatest from Microchip!
Contact: ***@***.***
|
Beta Was this translation helpful? Give feedback.
-
A question in two parts:
Beta Was this translation helpful? Give feedback.
All reactions