UART test

Topics regarding the Uzebox hardware/AVCore/BaseBoard (i.e: PCB, resistors, connectors, part list, schematics, hardware issues, etc.) should go here.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

UART test

Post by danboid »

Is there already a UART test app that prints a dump of whatever is being received via UART? If not, is there an easy way to test my UART headers are working?
rv6502
Posts: 80
Joined: Mon Feb 11, 2019 4:27 am

Re: UART test

Post by rv6502 »

Bridge the TX to RX pins with a wire and write a tiny app that send data and prints received data.
The Uzebox will talk to itself.

You can also get a 5V TTL USB-to-RS232 adapter for cheap (Amazon, etc) to test with the computer.

Make sure it's 5V.

A 3.3V one would work if that's all you have but put at least a 330 Ohm resistor in series the adapter's RX pin and don't connect the voltage pin.
The Uzebox can read 3.3V as a high signal, but a 3.3V adapter will not like getting 5V if it doesn't already have a resistor on its input already.

You only need Ground, RX, and TX.

Don't connect a PC's serial port directly, those usually output +12V=1 and -12V=0 on PCs and things can go poof.
They can even go up to +/- 25V
They'll also expect at least -3V below ground according to the RS-232 standard as a zero bit so you can't assume they'll accept the Uzebox's TTL ( 0V ) signal as a zero altho these days cheap hardware probably will.

You need a TTL adapter.

You can also make one using an AVR Arduino UNO or Mega board (and a few other 5V AVR Arduino boards. Not the ARM ones, on those the MCU talks to the USB port directly), write a dummy program that just sets TX and RX pins as inputs and does nothing so the microcontroller doesn't interfere.
You can then use the board's TX and RX pins. they go to the built-in USB-to-TTL adapter.

With other Arduino boards (like the Arduino Micro with an ATmega32U4, or ARM boards) you'll need to write a small program that relays the USB's serial to the TTL serial pins and vice-versa.

Again, 5V boards. Many ARM boards are less than 5V which you need a level-shifter or at least a resistor to not slam 5V from the Uzebox's TX pin into a 3.3V (or less) Arduino board's RX pin.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

My initial attempts at Uzebox MIDI via serial have been unsuccessful.

I am using a FTDI FT232R USB UART adapter with the voltage jumper set to 5V. I have a cable connected from the TXD pin on my FT232R to the RX pin on my Uzebox and I also connect the ground pin.

I built ttymidi from source (under Debian Testing) and I'm running it with the command:

Code: Select all

./ttymidi -b 57600
57600 being the supposed baud rate used by the Uzebox according to http://uzebox.org/wiki/UART

I am working off the presumption that Uzesynth should respond in realtime to any MIDI messages sent to one of the valid channels (via UART) provided that you aren't playing one of its demo tracks but it would be useful for me to know exactly what input Uzesynth is expecting to receive, MIDI wise. I've watched Artcfox's video on using Rosegarden to create music for the Uzebox and it seems he just has to assign a different MIDI program number to each UB/Rosegarden channel.

I am trying to get ttymidi and Uzesynth to work with qtractor. After starting JACK, ttymidi (using the above command) and qtractor and creating a MIDI track in qtractor assigned to MIDI program 1 then using the qjackctl graph window to connect the MIDI output of qtractor into the MIDI input of ttymidi, I can see the LED on FT232R pulsing in time to the MIDI messages qtractor is sending it but Uzesynth doesn't output any sound. I have tried using different MIDI channels/programs for the track in qtractor and using 'Omni' which should send it to all MIDI channels but I've not seen Uzesynth respond to any MIDI messages yet.

I'll do a video showing how I set up JACK, ttymidi and qtractor just in case anyone wants to follow along at home.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Here's a video to show exactly what I've been trying to get MIDI into Uzesynth.

I'm not sure that Uze said he's actually tested UART MIDI or if he just presumed it would work but I suspect its the latter.

https://youtu.be/SjIU-c_KQWM

I have sent that video to Alec, Rui (the author of qtractor and qjackctl) and the dev of ttymidi so anyone who might have something useful to say should get to see it.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Here's my message to Uze about this:

Hi Alec

I'm trying to send MIDI to Uzesynth via the UART RX header using ttymidi but I've not had any luck yet. Here's a video showing where I'm up to:

https://www.youtube.com/watch?v=SjIU-c_KQWM

I am presuming that Uzesynth should respond to MIDI voice control messages received via UART by default, provided its not playing one of the included demo songs?

What MIDI channel and program values are valid input for Uzesynth?

The Uzebox MIDI code seems to support using the UART instead of a dedicated MIDI port but has anyone ever tested MIDI via UART, with Uzesynth? Have you ever used Uzesynth via UART MIDI?

I've never attempted UART MIDI under Windows but there would seem to be at least a couple of apps that allow you to do that:

https://projectgus.github.io/hairless-midiserial/

https://www.spikenzielabs.com/learn/serial_midi.html

Thanks Alec!
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Rui has replied:

"I don't really know what ttymidi is about, but I know for sure that unless it talks cleanly to the alsa-sequencer interface, you'll have next to no chances for it to ever work at all."

I don't know enough about ALSA to comment. I've not tried ttymidi before and I don't know what else I could try it with without running ttymidi on one of my SBC's that's got UART headers like my RPi 4 but that test would be dependant on ttymidi working twice.

I should be able to write a simple UART test program but I'd need someone with a known working UART to verify it for me.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

I asked ChatGPT to write a Mode 9 (80 column) UART test program for the Uzebox and this is what it gave me.

Code: Select all

#include <avr/io.h>
#include <stdio.h>
#include "uzebox.h"

#define UART_RX_BUFFER_SIZE 80
char uart_rx_buffer[UART_RX_BUFFER_SIZE];

int main(void)
{
    uart_init();

    while (1)
    {
        int c = uart_getchar();
        if (c != EOF)
        {
            putchar(c);
            if (c == '\n')
            {
                uart_rx_buffer[UART_RX_BUFFER_SIZE - 1] = '\0';
                SetCursor(0, GetCursorY() + 1);
            }
        }
    }

    return 0;
}
I've not tried running this yet but I can see I'd need to at least replace SetCursor() and GetCursorY() with something based around GetTile(), maybe? Also, it doesn't seem to know about any of the Uzebox UART functions but unsurprisingly no one would've trained it on such an obscure thing so I suppose that's about as good as we can expect it to manage as is.

I'm mainly concerned about testing the RX is working but TX could be tested by sending strings each time the user pushes a joypad button like P1 UP, P1 A etc.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

Here's its second attempt after I tried correcting it on a couple of things:

Code: Select all

#include <avr/io.h>
#include <stdio.h>
#include "uzebox.h"

#define UART_RX_BUFFER_SIZE 80
char uart_rx_buffer[UART_RX_BUFFER_SIZE];

int main(void)
{
    InitUartRxBuffer();

    while (1)
    {
        int c = UartReadChar();
        if (c != EOF)
        {
            putchar(c);
            if (c == '\n')
            {
                uart_rx_buffer[UART_RX_BUFFER_SIZE - 1] = '\0';
                SetCursor(0, GetTile(0, GetCursorY() + 1));
            }
        }
    }

    return 0;
}
I'm not sure the SetCursor() bit is any less valid now its thrown a GetTile in there, I'm not sure that was a good suggestion.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

As per usual with ChatGPT pseudo code, I totally ignored what it suggested and I've hacked something together that almost works properly. This hack prints characters in the Uzenet demo recieved via UART RX but its not printing the correct characters yet. Hopefully someone can tell me why then we can get this cleaned up and maybe added as a new feature to the UzenetDemo?


In UzenetDemo.c, I changed the if statement around line 83 to look like this:

Code: Select all

if(wifi_Init(&wifiCallback)!=WIFI_OK){
		printf_P(PSTR("Init Error! Run the Uzenet configuration program\r\nto diagnose and/or configure the wifi module.\r\n"));
		UBRR0L=30;
		s16 test;
		while(1){
			test=UartReadChar();
			_cons_char(test);
		}
	}
So that when it fails to find the wifi module it just starts listening on the UART and printing whatever it receives.

I connected my USB serial adapter to my Uzebox and under Linux I ran:

Code: Select all

screen /dev/ttyUSB0 57600
To send characters over the serial link. I get characters when I press some keys on my keyboard (in the screen running terminal) but not the right ones. Maybe I'll have to work out how to use the UART buffer after all?

If we don't want UzenetDemo dropping straight into this test mode if it fails to find the wifi adapter then maybe UzenetDemo could enter a UART test mode like this if this user holds down a button (eg START on pad 1) when it is starting up.

UzenetDemo gives an init error for me and says I should run the Uzenet configuration program. Does that actually exist? My searching indicates it doesn't.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: UART test

Post by danboid »

http://uzebox.org/wiki/UART says that the Uzebox UART runs at 57600 baud but the UzenetDemo source would indicate it can handle 115200 bps.

Have you got a USB serial adapter Artcfox?
Post Reply