Looking for suggestions - 9 bit UART with Mega 2560

Hi everyone,

I posted here a few months ago, looking to figure out a way to communicate with a vintage Roland synthesizer using an Arduino (https://forum.arduino.cc/index.php?topic=560639.0). Basically I want to take an analog input from a potentiometer, and translate it to an 8-bit value, with the ability to play around with the 9th bit (which tells the synth if it's receiving address or parameter data).

A very nice Internet stranger has figured out the exact communication protocol and posted it here: https://xonik.github.io/mpg-200/pg-200/pg-200.html

I've attached the code I've assembled so far (much of it was based on suggestions from this forum, so thanks folks!) At the moment, I've set up the serial monitor to print the 8 bit values coming from my pot, but it's still not communicating with my synth.

void setup() {
    Serial.begin(9600);
//const unsigned int MYUBRR = (16000000UL/16) / 31250 - 1;
} 
void USART_Init( unsigned int ubrr)
  /*Set baud rate */
{   
UBRR0H = (byte) (ubrr >> 8); 
  UBRR0L = (byte) ubrr;
  /* Set frame format: 9 data bits, 1 stop bit, no parity */ 
  UCSR0C = (7 << UCSZ00);
  /* Enable transmitter */ 
  UCSR0B =  (1 << TXEN0);
}

void loop() {
  // put your main code here, to run repeatedly:
  // read the input on analog pin 1:
  int sensorValue = analogRead(A1);
  // Convert the analog reading (which goes from 0 - 1023) to 8-bits (0-255),
  // which will be used to simulate the pot values sent by the PG-200.
  int cutoff = sensorValue * (255.0 / 1023.0);
  // Set up an if statement
      if (A1 >= 0);
      {
      unsigned int addressa1 = 23;
      UCSR0B |= (1);
      }
void USART_Transmit( unsigned int data );
  /* Wait for empty transmit buffer */ 
while ( !( UCSR0A & (1<

A few things I'm looking for advice on are how to send the address and value frames properly. Any other suggestions would be much appreciated!

This code doesn't do anything reasonable. It's just a wild copy/paste from other sources. Don't expect use to do the programming for you.

First off, you want to know if the Serial class will do what you need it to do. Looking at the Protocol basics, you need to write in 9N1 at 31250 baud. I don't see a way to configure Serial.begin() for 9N1, so you will need to write your own "bit bang" method.

I don't see a way to configure Serial.begin() for 9N1, so you will need to write your own "bit bang" method.

No, you don't, the hardware supports 9bit UART but the Serial object doesn't support it. You have to use a patched version of the HardwareSerial class (incompatible with the standard implementation!) to do 9bit operation. Nick Gammon wrote such a library and OP already got that link in it's previous thread about the same topic.