I think I have increased the Tx buffer size for Serial2 but when I run Serial2.availableForWrite() it still shows the small value.
I'm having serial midi problems with a Sequential synth occasionally receiving corrupted data, so I'm trying to increase the Tx buffer to see if this will help. I've changed SERIAL2_TX_BUFFER_SIZE from 40 to 512 in Serial1.c and Serial2.c in ...avr/cores/teensy3 and recompiled. The problem is still there and when I repeatedly run Serial2.availableForWrite() it still shows 39.
Serial2.c
////////////////////////////////////////////////////////////////
// Tunable parameters (relatively safe to edit these numbers)
////////////////////////////////////////////////////////////////
#ifndef SERIAL2_TX_BUFFER_SIZE
#define SERIAL2_TX_BUFFER_SIZE 512 // number of outgoing bytes to buffer was 40
#endif
#ifndef SERIAL2_RX_BUFFER_SIZE
#define SERIAL2_RX_BUFFER_SIZE 512 // number of incoming bytes to buffer was 64
#endif
#define RTS_HIGH_WATERMARK (SERIAL2_RX_BUFFER_SIZE-24) // RTS requests sender to pause
#define RTS_LOW_WATERMARK (SERIAL2_RX_BUFFER_SIZE-38) // RTS allows sender to resume
#define IRQ_PRIORITY 64 // 0 = highest priority, 255 = lowest
Have I not increased the buffer size correctly or am I not reading or interpreting the reported value correctly?
Would increasing the Tx buffer size help me anyway? All transmitted messages come from the Teensy so I'm not concerned with incoming messages. I'm generating midi CCs in the Teensy 3.6 from an LFO and from an interrupt driven clock. IF the Tx buffer does fill up then I thought the Teensy would just halt until it's free again and then continue? Do the interrupt driven clocks mess with this and cause corruption?
Test program compiled (I believe) using the Serial2.c changes above, showing the clock function I use:
Thanks
I'm having serial midi problems with a Sequential synth occasionally receiving corrupted data, so I'm trying to increase the Tx buffer to see if this will help. I've changed SERIAL2_TX_BUFFER_SIZE from 40 to 512 in Serial1.c and Serial2.c in ...avr/cores/teensy3 and recompiled. The problem is still there and when I repeatedly run Serial2.availableForWrite() it still shows 39.
Serial2.c
////////////////////////////////////////////////////////////////
// Tunable parameters (relatively safe to edit these numbers)
////////////////////////////////////////////////////////////////
#ifndef SERIAL2_TX_BUFFER_SIZE
#define SERIAL2_TX_BUFFER_SIZE 512 // number of outgoing bytes to buffer was 40
#endif
#ifndef SERIAL2_RX_BUFFER_SIZE
#define SERIAL2_RX_BUFFER_SIZE 512 // number of incoming bytes to buffer was 64
#endif
#define RTS_HIGH_WATERMARK (SERIAL2_RX_BUFFER_SIZE-24) // RTS requests sender to pause
#define RTS_LOW_WATERMARK (SERIAL2_RX_BUFFER_SIZE-38) // RTS allows sender to resume
#define IRQ_PRIORITY 64 // 0 = highest priority, 255 = lowest
Have I not increased the buffer size correctly or am I not reading or interpreting the reported value correctly?
Would increasing the Tx buffer size help me anyway? All transmitted messages come from the Teensy so I'm not concerned with incoming messages. I'm generating midi CCs in the Teensy 3.6 from an LFO and from an interrupt driven clock. IF the Tx buffer does fill up then I thought the Teensy would just halt until it's free again and then continue? Do the interrupt driven clocks mess with this and cause corruption?
Test program compiled (I believe) using the Serial2.c changes above, showing the clock function I use:
Code:
#include <uClock.h>
#include <SD.h>
#include <EEPROM.h>
#include <ResponsiveAnalogRead.h> // https://github.com/dxinteractive/ResponsiveAnalogRead
#include <Adafruit_CharacterOLED.h>//include the OLED library
#define SD_CS BUILTIN_SDCARD // if compile fails here it's because you've installed the standards SD library and compiler is using that instead of Teensy one. Delete the standard one's folder
const int versionVersion = 2; const int versionMajor = 0; const int versionMinor = 29;
const int errorReporting = 0;
Adafruit_CharacterOLED lcd(OLED_V2, 2, 3, 4, 5, 6, 7, 8); // 2004 OLED!
// GND (pin 1) to GND * VDD (pin 2) to 5V * RS (pin4) to digital pin 2 * R/W (pin 5) to digital pin 3 * Enable (pin 6) to digital pin 4 * D4 (pin 11) to digital pin 5 * D5 (pin 12) to digital pin 6 * D6 (pin 13) to digital pin 7 * D7 (pin 14) to digital pin 8
Sd2Card card;
#define MIDI_CLOCK 0xF8
#define MIDI_START 0xFA
#define MIDI_STOP 0xFC
const float snapMultiplier = 0.003; const bool responsiveSleep = true; // previously 0.005
ResponsiveAnalogRead analog [] {{A0, responsiveSleep, snapMultiplier}, {A1, responsiveSleep, snapMultiplier}, {A2, responsiveSleep, snapMultiplier}, {A3, responsiveSleep, snapMultiplier}, {A4, responsiveSleep, snapMultiplier}, {A5, responsiveSleep, snapMultiplier}, {A6, responsiveSleep, snapMultiplier}, {A7, responsiveSleep, snapMultiplier}, {A8, responsiveSleep, snapMultiplier}, {A9, responsiveSleep, snapMultiplier}, {A10, responsiveSleep, snapMultiplier}, {A11, responsiveSleep, snapMultiplier}, {A12, responsiveSleep, snapMultiplier}, {A13, responsiveSleep, snapMultiplier}, {A14, responsiveSleep, snapMultiplier}, {A15, responsiveSleep, snapMultiplier}, {A16, responsiveSleep, snapMultiplier}, {A17, responsiveSleep, snapMultiplier}, {A18, responsiveSleep, snapMultiplier}, {A19, responsiveSleep, snapMultiplier}, {A20, responsiveSleep, snapMultiplier}};
elapsedMillis steveTimer1;
const int switchPins[] = {30, 11}; // prototype v2 was 9,11 v3 is 30,11
const int ledPins[] = {13, 12};
const int muxE = 24, muxS0 = 25, muxS1 = 26, muxS2 = 27, mux1out = 28, mux2out = 29;
void setup() {
Serial.begin(9600);//diagnostic serial port
Serial1.begin(31250); //In 1 and Thru
Serial2.begin(31250); //In2 and Out
delay(100);
Serial.println("Starting...");
pinMode(switchPins[0], INPUT_PULLUP); pinMode(switchPins[1], INPUT_PULLUP); pinMode(ledPins[0], OUTPUT); pinMode(ledPins[1], OUTPUT);
pinMode(muxE, OUTPUT); pinMode(muxS0, OUTPUT); pinMode(muxS1, OUTPUT); pinMode(muxS2, OUTPUT); pinMode(mux1out, INPUT_PULLUP); pinMode(mux2out, INPUT_PULLUP);
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message.
uClock.setClock96PPQNOutput(ClockOut96PPQN);
int clockTempo = 120;
uClock.setTempo(clockTempo);
}
void loop() {
if (steveTimer1 >= 10){
Serial.print("availableForWrite: ");
Serial.println(Serial2.availableForWrite());
steveTimer1 = steveTimer1 -10;
}
}
// The callback function wich will be called by Clock each Pulse of 96PPQN clock resolution.
void ClockOut96PPQN(uint32_t * tick) {
Serial2.write(MIDI_CLOCK);
}