Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

2 Serial Devices on one board

Hello all,

I am currently working on a project in which I need to connect two digital sensors, a Temp & Humidity sensor(SHT 15) and an accelerometer (ADXL345) both digital sensors. They also both use serial communications, and I'm not sure how to connect both of them to the board to be able to have them both run.

My ideology is to have one run through the RS232 port... and the other ???

Create a serial connection through the Expansion Headers? Is this even possible?

The simplest solution would be best, because I'm sure as you can see by reading, I am a beginner.

Thanks

PS I'm using the DE2 Development board

10 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Read the data sheet for the sensors carefully.

    Since you are a beginner, I will provide a little bit of terminology;

    1. UART

    Universal Asynchronous Receiver/Transmitter.

    Also known as a serial port.

    2. RS232

    Level-shifted (and inverted) UART transmit and receive signals.

    If your sensor data sheet states that the signals are logic level, eg., 3.3V signals, then the signals are the output of a UART. If the data sheet states that the signals are RS232, then they are level shifted, and will probably be +/-10V signals. Measure the signals with an oscilloscope and see.

    If the signals are UART logic levels, then you can instantiate a pair of UARTs in the FPGA and control the sensors directly.

    If the signals are RS232 levels, then you need a level translator, i.e., an RS232 level to logic level translator. The DE2 has a serial port - check the schematic and see if there are enough level translators on the DB9 for either one or both sensors. Sparkfun and other microcontroller online stores will have cheap boards with RS232 level translators and 100-mil header connectors that you can use.

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    IIRC the SHT sensor uses an I2C bus, which is another serial protocol. You will need some external pull-ups (or maybe use the FPGA's internal ones) and find a bus controller IP. There is one available on opencores (http://opencores.org).

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    IIRC RS232 should be +12v/-12v negative logic (-12v is a logic 1), however a lot of modern systems only drive a much lower range, possibly even +5v/0v!

    However the receivers have to allow for the full voltage range.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    I didn't get a chance to look at the data sheets yesterday ... your comment about RS232 threw me off on the wrong track ...

    --- Quote Start ---

    I am currently working on a project in which I need to connect two digital sensors, a Temp & Humidity sensor(SHT 15) and an accelerometer (ADXL345) both digital sensors. They also both use serial communications

    --- Quote End ---

    The ADXL345 can be accessed via either SPI or I2C, so the device can be connected directly to pins on the expansion header. The DE0-nano contains the ADXL345 device, so there should be examples you can use with that board.

    The SHT15 sensor

    http://www.sparkfun.com/datasheets/sensors/sht1x_datasheet.pdf

    uses a non-standard serial protocol, which uses a serial clock and bidirectional serial data, where the data signal should only ever be driven low to avoid driver conflict. You will have to create a custom interface to this device, I'd recommend starting with bit-banged I/O, where the clock signal is driven as an output and the data controls the enable on a tri-state buffer that will drive low when enabled.

    Both of these devices can be interfaced directly to your FPGA pins. You would not use an RS232 level translator.

    Try coding up an interface, and if you have trouble, ask questions here on the forum.

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    So from what I have gathered from everyone's responses is that the ADXL345 is going to work well since I can connect to the SPI/I2C Core on the board using the expansion headers.

    The SHT15 however, is not so nice since it will require me writing its own protocol in Verilog(I Assume?) ...

    Sorry if this seems basic, but in our class we only scratched the surface of using the SPI and we were supposed to write our own protocol but the teacher scrapped that due to us falling behind.

    Are the questions I'm asking clear? Should I just find another temp and humidity sensor to better work with the board, or that uses the standard protocol?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The SHT15 sensor uses a non-standard serial protocol, which uses a serial clock and bidirectional serial data

    --- Quote End ---

    Oh yes sorry about that, the SHT15 doesn't use standard I2C. We are actually using a SHT2x in one of our projects, which does use I2C, and I just assumed the STH1x were the same.

    You are write, you will have to write a custom component to access it, or as dave says use bit banged i/o, with PIOs for example.

    If you really need the humidity you can try the SHT20 instead, that uses a I2C bus. If you only need temperature there are lots of other I2C sensors, such as the FM75.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    So from what I have gathered from everyone's responses is that the ADXL345 is going to work well since I can connect to the SPI/I2C Core on the board using the expansion headers.

    The SHT15 however, is not so nice since it will require me writing its own protocol in Verilog(I Assume?) ...

    --- Quote End ---

    Yep, you've got it.

    --- Quote Start ---

    Sorry if this seems basic, but in our class we only scratched the surface of using the SPI and we were supposed to write our own protocol but the teacher scrapped that due to us falling behind.

    --- Quote End ---

    Since you are not familiar with programming in HDL, then you probably want to find another sensor that has an I2C or SPI interface.

    Cheers,

    Dave
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok, we have invested in a new SHT21 which uses I2C.

    Now when building our system in SOPC builder, I have added a SPI(3-wire interface) for the ADXL345 under Interface Protocols->Serial->SPI(3 wire interface).

    Setup:

    Type-Master

    Number of Selects-1

    SCLK-4900000

    Data width- 32 bits

    Shift- MSB

    Clock Polarity and Phase-0

    My real question lies in the implementation of I2C protocol. I don't see a core for I2C implementation.. any advice? OpenCores.org?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    My real question lies in the implementation of I2C protocol. I don't see a core for I2C implementation.. any advice? OpenCores.org?

    --- Quote End ---

    The DE0-nano examples provided by Terasic use bit-banging to implement the I2C protocol. If you're going to use a NIOS II core, then that would be my recommendation.

    I believe others have used the OpenCore's I2C core. Search the archive.

    Cheers,

    Dave