Author Topic: SPI-slave to UART  (Read 5871 times)

0 Members and 2 Guests are viewing this topic.

Offline BoomerangTopic starter

  • Regular Contributor
  • *
  • Posts: 52
SPI-slave to UART
« on: July 09, 2017, 12:33:29 pm »
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!
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: SPI-slave to UART
« Reply #1 on: July 09, 2017, 12:47:02 pm »
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.
 

Offline BoomerangTopic starter

  • Regular Contributor
  • *
  • Posts: 52
Re: SPI-slave to UART
« Reply #2 on: July 09, 2017, 01:02:52 pm »
Arduino is too big to fit in the case of the device.

If there is a single chip converter will be perfect!
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: SPI-slave to UART
« Reply #3 on: July 09, 2017, 01:06:49 pm »
If there is a single chip converter will be perfect!

FTDI makes lots of USB-to-whatever chips. They must have USB-to-SPI as well.
 

Offline julian1

  • Frequent Contributor
  • **
  • Posts: 735
  • Country: au
Re: SPI-slave to UART
« Reply #4 on: July 09, 2017, 10:04:56 pm »
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
 

Offline joshtyler

  • Contributor
  • Posts: 36
  • Country: gb
Re: SPI-slave to UART
« Reply #5 on: July 10, 2017, 01:21:09 am »
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

This is probably the easiest solution (also great tutorial julain1).

It's worth noting however that in this case only a FT232H (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 an app note  and design example, for SPI using the D2XX drivers, as well as an open source wrapper for D2XX in 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!
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: SPI-slave to UART
« Reply #6 on: July 10, 2017, 12:46:55 pm »
microchip makes usb to whatever adapters too but i can't comment on their quality as i never used them
http://www.microchip.com/wwwproducts/en/MCP2210
 

Offline BoomerangTopic starter

  • Regular Contributor
  • *
  • Posts: 52
Re: SPI-slave to UART
« Reply #7 on: July 10, 2017, 01:00:37 pm »
microchip makes usb to whatever adapters too but i can't comment on their quality as i never used them
http://www.microchip.com/wwwproducts/en/MCP2210

This is not for my case - it's SPI-Master only.
 

Online gamalot

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: au
  • Correct my English
    • Youtube
Re: SPI-slave to UART
« Reply #8 on: July 10, 2017, 01:27:06 pm »
STM32 Nucleo

Offline Codebird

  • Regular Contributor
  • *
  • Posts: 161
  • Country: gb
Re: SPI-slave to UART
« Reply #9 on: July 10, 2017, 01:37:24 pm »
Quote
Arduino is too big to fit in the case of the device.

Arduino pro mini. Smallest arduino. There's barely enough room on there for the atmega chip, crystal and reset button.
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: SPI-slave to UART
« Reply #10 on: July 10, 2017, 02:50:25 pm »
microchip makes usb to whatever adapters too but i can't comment on their quality as i never used them
http://www.microchip.com/wwwproducts/en/MCP2210

This is not for my case - it's SPI-Master only.

understood.
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/PIC16F15313
8 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 issue

or, with USB
http://www.microchip.com/wwwproducts/en/PIC16F1454

don'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
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3146
  • Country: ca
Re: SPI-slave to UART
« Reply #11 on: July 10, 2017, 02:52:24 pm »
Quote
Arduino is too big to fit in the case of the device.

Arduino pro mini. Smallest arduino. There's barely enough room on there for the atmega chip, crystal and reset button.

Or PIC16F1454. It is 4x4 mm in QFN package.

<edit>and it doesn't require a crystal, or anything else except a decoupling capacitor.
« Last Edit: July 10, 2017, 02:54:21 pm by NorthGuy »
 
The following users thanked this post: JPortici

Offline BoomerangTopic starter

  • Regular Contributor
  • *
  • Posts: 52
Re: SPI-slave to UART
« Reply #12 on: July 11, 2017, 08:22:34 am »
Thanks for the replys!

It seems that using FT2232H with LibMPSSE-SPI will be the best option.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3507
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: SPI-slave to UART
« Reply #13 on: July 11, 2017, 09:15:00 am »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf