Ok let me try to explain this better. Here is my proposed setup for a versatile speech chip interface.
I have a TTS256 Text to speech chip talking to a speakjet chip directly. (9600 baud into the TTS)
I also have a serial LCD screen (9600 baud into the LCD)
I will be hooking these two things up to an Arduino Pro Mini.
There will be a total of three serial ports being dealt with.
- Soft serial to the TTS at 9600
- Soft serial to the LCD at 9600
- Hardware serial that will be TTL level serial port for an FTDI or MAX232 hookup to varied devices.
What I hope to have is a system that I can hook various machines up to and use the TTS circuitry with status updated on the Serial LCD. There are many things I want to hook up to this setup. Everything from an old Commodore Vic 20 for TTS games to a PC using a FTDI at say 115200 baud.
I have already done a bit of programming in regards to this and I have listed a p[ortion of this below. It compiles just fine and I believe once I get everything wired up that I can get it to work if everything is set to 9600 baud, but I feel I might need extra buffering seeing as how 115200 max baud is is more than 2300 times the minimum baud of 50.
#include <SoftwareSerial.h>
// Define pins for serial ports
// SoftwareSerial object(rx,tx);
SoftwareSerial TTSSerial(10,11); //Pin 10 goes to Pin 5(TX) on TTS256 chip Pin 11 goes to Pin 18(RX) on TTS256 chip
SoftwareSerial LCDSerial(12,13); //Pin 12 not used Pin 13 goes to RX on LCD
//Define Pins for other function
int SJRst = 2; //Speakjet Reset Pin 11 active LOW
int TTSRst = 3; //Text to Speech reset pin 1 active HIGH
int SJBuf = 4; //Speakjet Buffer Hald Full Pin 15
int SJSpeak = 5; //Speakjet Speaking Pin 16
int SJReady = 6; //Speakjet Read Pin 17
int Mode = 7; //Pin for button to toggle Pass Through Mode
int Debug = 8; //Pin for button to toggle DEBUG Mode
int LCDLum = 9; //Pin to control LCD Illumination
int BaudPin1 = 14; //Pin to add value of 1 to Val for baud rate setting
int BaudPin2 = 15; //Pin to add value of 2 to Val for baud rate setting
int BaudPin3 = 16; //Pin to add value of 4 to Val for baud rate setting
int BaudPin4 = 17; //Pin to add value of 8 to Val for baud rate setting
//Define Variables
long debounce = 100; //Debounce time 100 mSec
int UpdDis; //Update Display Flag when status changes
int byteReceived;
// Define Mode Button Variables
int ModeFlg = HIGH;
int ModRead;
int pModeFlg = LOW;
long ModeTime = 0;
//Define Debug Button Variables
int DBFlg = HIGH;
int DBRead;
int pDBFlg = LOW;
long DBTime = 0;
//Define Speakjet Ready Variables
int SJRFlg = HIGH;
int SJRRead;
int pSJRFlg = LOW;
//Define Speakjet Speaking Variables
int SJSFlg = HIGH;
int SJSRead;
int pSJSFlg = LOW;
//Define Speakjet Buffer Variables
int SJBFlg = HIGH;
int SJBRead;
int pSJBFlg = LOW;
//Define LCD Illumination Variable
int IlumRead;
int pIlumFlg = LOW;
long IlumTime = 0;
//Valid baud rates to select from
long BaudRate[16] = {50,75,110,300,600,1200,2400,4800,9600,14400,19200,28800,
38400,56000,57600,115200} ;
//Value of which array will be used for BaudRate
int bVal = 0;
//String used to display baud rate
String BaudStr;
//Valid screen illumination values
int IlumValue[4] = {128,140,150,157};
//Value of which array with be used for Illumination
int iVal = 0;
void setup() {
//Define Pin direction
pinMode(SJRst, OUTPUT);
pinMode(TTSRst, OUTPUT);
pinMode(SJBuf, INPUT);
pinMode(SJSpeak, INPUT);
pinMode(SJReady, INPUT);
pinMode(Mode, INPUT);
pinMode(Debug, INPUT);
pinMode(LCDLum, INPUT);
pinMode(BaudPin1, INPUT);
pinMode(BaudPin2, INPUT);
pinMode(BaudPin3, INPUT);
pinMode(BaudPin4, INPUT);
//Reset TTS and Speakjet
digitalWrite(SJRst, LOW); //Hold Speakjet reset low
digitalWrite(TTSRst, HIGH); //Hold TTS reset high
delay(300);
digitalWrite(SJRst, HIGH); //Activate SJ
delay(300);
digitalWrite(TTSRst, LOW); //Activate TTS
delay(300);
//Open communication ports
LCDSerial.begin(9600); // set up LCD serial port for 9600 baud
delay(500); // wait for display to boot up
TTSSerial.begin(9600); // set up TTS serial port for 9600 baud
//Determine baud rate to host processor and open
if ( digitalRead(BaudPin4) == HIGH) {bVal = bVal + 8;}
if ( digitalRead(BaudPin3) == HIGH) {bVal = bVal + 4;}
if ( digitalRead(BaudPin2) == HIGH) {bVal = bVal + 2;}
if ( digitalRead(BaudPin1) == HIGH) {bVal = bVal + 1;}
Serial.begin(BaudRate[bVal]);
BaudStr = "Baud Rate: " + BaudRate[bVal];
//Initialize LCD
LCDSerial.write(254); // clear screen
LCDSerial.write(1);
LCDSerial.write(254); // move cursor to beginning of first line
LCDSerial.write(128);
LCDSerial.print(BaudStr);
LCDSerial.write(254); // move cursor to beginning of second line
LCDSerial.write(192);
LCDSerial.print("Mode:");
LCDSerial.write(254); // move cursor to beginning of third line
LCDSerial.write(148);
LCDSerial.print("Debug:");
LCDSerial.write(254); // move cursor to beginning of forth line
LCDSerial.write(212);
LCDSerial.print("Status:");
updateDisplay( 0, 0, 0, 0, 0);
}
void loop() {
UpdDis = LOW;
ModRead = digitalRead(Mode);
DBRead = digitalRead(Debug);
SJRRead = digitalRead(SJReady);
SJSRead = digitalRead(SJSpeak);
SJBRead = digitalRead(SJBuf);
IlumRead = digitalRead(LCDLum);
//Check if Mode button was pressed
if (ModRead == HIGH && pModeFlg == LOW && millis() - ModeTime > debounce) {
if (ModeFlg == HIGH) {
ModeFlg = LOW;
TTSSerial.println("X");
}
else {
ModeFlg = HIGH;
TTSSerial.println("passthruon");
}
ModeTime = millis();
UpdDis = HIGH;
}
//Check if Debug button was pressed
if (DBRead == HIGH && pDBFlg == LOW && millis() - DBTime > debounce) {
if (DBFlg == HIGH) {
DBFlg = LOW;
TTSSerial.println("debugoff");
}
else {
DBFlg = HIGH;
TTSSerial.println("debugon");
}
DBTime = millis();
UpdDis = HIGH;
}
//Check if Illumination Button was pressed
if (IlumRead == HIGH && pIlumFlg == LOW && millis() - IlumTime > debounce) {
//Send command to LCD to change value of illumination
LCDSerial.write(124);
LCDSerial.write(IlumValue[iVal]);
iVal = iVal + 1; //Bump iVal to use next Illumination Value
if (iVal > 3) iVal = 0; //If iVal is greater than 3 then set back to Zero to turn off Illumination
IlumTime = millis();
}
//Check if Speakjet Ready Pin is HIGH
if (SJRRead == HIGH && pSJRFlg == LOW) {
if (SJRFlg == HIGH)
SJRFlg = LOW;
else
SJRFlg = HIGH;
UpdDis = HIGH;
}
//Check if Speakjet Speaking Pin is HIGH
if (SJSRead == HIGH && pSJSFlg == LOW) {
if (SJSFlg == HIGH)
SJSFlg = LOW;
else
SJSFlg = HIGH;
UpdDis = HIGH;
}
//Check if Buffer Half Full Pin is HIGH
if (SJBRead == HIGH && pSJBFlg == LOW) {
if (SJBFlg == HIGH)
SJBFlg = LOW;
else
SJBFlg = HIGH;
UpdDis = HIGH;
}
if (UpdDis == HIGH) {
updateDisplay(ModeFlg, DBFlg, SJRFlg, SJSFlg, SJBFlg);}
//route serial data from serial to TTS
//
//Route serial data from TTS to serial
pModeFlg = ModRead;
pDBFlg = DBRead;
pSJRFlg = SJRRead;
pSJSFlg = SJSRead;
pSJBFlg = SJBRead;
//Check for data coming from Host serial port and route to TTS chip
if (Serial.available())
TTSSerial.write(Serial.read());
//Check for data coming from the TTS chip and route to Host serial port
if (TTSSerial.available())
byteReceived = TTSSerial.read();
if (byteReceived > 127) {
if (byteReceived < 31) {
Serial.write(byteReceived);
}
else if (byteReceived == 13) {
Serial.write(byteReceived);
}
}
}