SPI-slave to UART - Page 1
Forum section: electronics / general

author: Boomerang
author_rank: Regular Contributor
timestamp: July 09, 2017, 12:33:29 pm
content: Hi to all,I have a device that sends twice per second few bytes on it's SPI bus. The clock is ~ 16 kHz. I want to log those bytes with a PC. What you will recommend me to use to convert the SPI interface to UART? I don't care if it's real RS232 or it's a pseudo-RS (virtual serial port over USB). The important for me is to be able to log the data by my software using serial port API.Thanks!

author: sokoloff
author_rank: Super Contributor
timestamp: July 09, 2017, 12:47:02 pm
content: The easiest off the shelf thing is probably an Arduino. (If you don't want to do any research on "which one?", just order an Uno R3; it'll work fine.)No significant electronics experience needed and ample code snippets around for both SPI and serial writing.

author: Boomerang
author_rank: Regular Contributor
timestamp: July 09, 2017, 01:02:52 pm
content: Arduino is too big to fit in the case of the device.If there is a single chip converter will be perfect!

author: NorthGuy
author_rank: Super Contributor
timestamp: July 09, 2017, 01:06:49 pm
content: Quote from: Boomerang on July 09, 2017, 01:02:52 pmFTDI makes lots of USB-to-whatever chips. They must have USB-to-SPI as well.

author: julian1
author_rank: Frequent Contributor
timestamp: July 09, 2017, 10:04:56 pm
content: You can do USB<->SPI slave with a FT2232H and FTDI’s libftdi USB library. Uart is not desirable because of the more complicated clock timing requirements on both sides of the comm.The main thing is to put the ftdi device into MPSSE mode instead of uart mode. This allows it to speak SPI.I wrote a short article about doing this with a fpga acting as SPI slave. You can ignore the fpga part, and see the code at, "Programming the FT2223H using libftdi",http://blog.julian1.io/2017/01/29/icestick-ftdi-spi.html

author: joshtyler
author_rank: Contributor
timestamp: July 10, 2017, 01:21:09 am
content: Quote from: julian1 on July 09, 2017, 10:04:56 pmThis is probably the easiest solution (also great tutorial julain1).It's worth noting however that in this case only aFT232H(the slightly simpler single channel version of the FT2232H) would be needed. Also that libftdi isn't actually FTDI's library to talk to the chip, it is an open source replacement. FTDI offer their own closed source, but cross platform,D2XX drivers.FTDI provide anapp noteanddesign example, for SPI using the D2XX drivers, as well asan open source wrapper for D2XXin SPI mode to help you off the ground.I've used both libftdi, and D2XX in the past, and whilst I prefer libftdi for the community support and open-source codebase. I've found that the D2XX drivers are easier to get going quickly thanks to FTDI's excellent documentation. The whole legacy libftdi, vs up to date libftdi (aka libftdi vs libftdi2), and the libftdi C++ wrapper which seems nice, but I simply could not get to work, does confuse things a bit too!

author: JPortici
author_rank: Super Contributor
timestamp: July 10, 2017, 12:46:55 pm
content: microchip makes usb to whatever adapters too but i can't comment on their quality as i never used themhttp://www.microchip.com/wwwproducts/en/MCP2210

author: Boomerang
author_rank: Regular Contributor
timestamp: July 10, 2017, 01:00:37 pm
content: Quote from: JPortici on July 10, 2017, 12:46:55 pmThis is not for my case - it's SPI-Master only.

author: gamalot
author_rank: Super Contributor
timestamp: July 10, 2017, 01:27:06 pm
content: STM32 Nucleo

author: Codebird
author_rank: Regular Contributor
timestamp: July 10, 2017, 01:37:24 pm
content: QuoteArduino pro mini. Smallest arduino. There's barely enough room on there for the atmega chip, crystal and reset button.

author: JPortici
author_rank: Super Contributor
timestamp: July 10, 2017, 02:50:25 pm
content: Quote from: Boomerang on July 10, 2017, 01:00:37 pmunderstood.If you can live with an UART and then connect it to a USB-TTL dongle, and are up to program another chip, then why not use the smallest micro with both SPI and UART?http://www.microchip.com/wwwproducts/en/PIC16F153138 pin of which- 2 for VDD, GND- 1 for UART RX (fixed)- 1 for MCLR, but it can disabled so you can use it as the /SS input- 4(5 with MCLR) GPIOs which can be connected to any digital peripheral through PPS, so TX,SCK,SDO,SDI(,/SS)as small as a 3x3 dfn if space is really an issueor, with USBhttp://www.microchip.com/wwwproducts/en/PIC16F1454don't know if can do crystal-less USB though. but yeah, open the virtual com example, add the spi part to the code and you're good to go

author: NorthGuy
author_rank: Super Contributor
timestamp: July 10, 2017, 02:52:24 pm
content: Quote from: Codebird on July 10, 2017, 01:37:24 pmOr PIC16F1454. It is 4x4 mm in QFN package.<edit>and it doesn't require a crystal, or anything else except a decoupling capacitor.

author: Boomerang
author_rank: Regular Contributor
timestamp: July 11, 2017, 08:22:34 am
content: Thanks for the replys!It seems that using FT2232H with LibMPSSE-SPI will be the best option.

author: technix
author_rank: Super Contributor
timestamp: July 11, 2017, 09:15:00 am
content: Some more alternatives:* SC16IS752 if you don't mind rewriting some code on the gadget. It is a full blown SPI slave to UART chip. You will need driver on the gadget though.* PIC16F1455 the smallest USB-capable microcontroller in DIP package I can find. It can do 5V and 3.3V and have built in LDO for 3.3V USB operation. It can also function as a clock generator for your system.* STM32F042F6P6 the smallest USB-capable microcontroller in TSOP package I can find. 3.3V operation.