cancel
Showing results for 
Search instead for 
Did you mean: 

Mini thermal printer and STM32 MCU with 1 SPI free - best way to connect?

HTD
Senior III

I have 2 different mini thermal printers with RS-232 TTL interfaces. Different manufacturers, but I suspect the interface is identical or very similar. Both manufacturers state TTL interface.

On the other side I have STM32 MCU with 1 free SPI.

My limitation is I can't use UART. I don't have free UART pins on my board. I have only 1 SPI port free.

For what I've read - MAX3100 solves the SPI -> UART problem, MAX3232 solves CMOS 3V3 -> TTL 5V problem. But it's too expensive combined and I would have to add 2 chips that would make my device also more difficult to make.

Do you know a cheaper / simpler solution? Maybe a printer similar to Adafruit Mini Thermal Printer, but with SPI interface? A cheaper all-in-one interface chip? There is MAX3110E / MAX3111E, but I read it's discontinued / obsolete. What is currently commonly used?

BTW, I know there are printers with just every possible interfaces, but they are way too expensive, I'm looking for the cheapest possible printer, the cheapest possible way to connect it to my MCU.

5 REPLIES 5

Given you did not care to give us the least relevant info - which STM32, what baudrate, duplex or simplex (Tx only) communication - help is rather limited.

Tx UART can be simulated by SPI in a quite trivial manner. Rx is less so.

UART has also been traditionally bit-banged.

JW

Well, all relevant info is here, STM32 using 3.3V CMOS SPI, that's the port I want to use, as for the printer, the Chinese manufacturer gives even less information, RS232/TTL it's all I have. I'd guess RS232 is duplex, however, maybe the printer could work with simplex connection? I'm not sure, maybe I'll just test it, I could temporarily use one of my busy UARTs to see if it would work with simplex, then - as you say, bit-banging, or... I could switch my 1-wire interface to bit banging and get 1 free UART.

S.Ma
Principal

If you are not using uart continuously, you could check reassigning io pins to have 1 uart time multiplex to 2 buses, depending on your pinout. If you need uart tx amd rx, another way with low baud rate is timer capture compare.

I solved this by assigning UART to the printer (no level conversion used, its port standard was 3-5V), also, UART pins on my MCU are 5V tolerant. It works very well. I also needed a 1-wire communication that is used non-stop, so I use just 1 GPIO pin and I made bit-banging driver that uses a timer to provide 1us timing accuracy without high CPU load. I just set the timer ARR to the exact value I need for the next pulse. Not exactly exact, because there is a lag between enabling the timer and the actual counting. But I measure this lag on driver initialization and it's taken into account. The communication works surprisingly reliable. The jitter observed on the oscilloscope is negligible, also nothing in my app lags, and the app does a lot of things each millisecond (mostly it measures low frequency signals and filters the noise from them). There's also GUI - it still works with stable 60FPS, no lags.

BTW, I think I could use bit banging also for the printer. It would probably work fine. It would be a little more difficult to implement because I would have to implement a printing buffer. When I read a sensor over 1-wire, there's so little data transferred that things like DMA would not even be very usable for performance.

S.Ma
Principal

If you can use a timer for 1 bit HW support, it is better than nothing. Some STM32 DMA can read/write on capture/compare timer registers. At some point you will wonder the WCET of your app, start to manage overrun flags in interrupt, and quote the application severity of a late interrupt, which is case by case.