BV518

Serial Mass Storage device

This is a mass storage device, serial data can be stored and retrieved and in addition the resulting file can be read by any PC using the FAT file system - All windows and Linux PC's

In addition it also has its own I/O and so can be used as a stand alone system.

Physical Details

The Board consists of a serial interface, 3.3V regulator, Microcontroller and Micro SD Card holder. The device can be used with either 5V or 3.3V logic. The SD Card can be any SD Card up to 32GB,this is inserted into the holder at the end of the device.

Serial Connections

  • RX Input
  • TX Output
  • V+ Power supply 3.5V to 10V
  • DT - reset can leave disconnected
  • GN Ground
The serial by default is set for 115200 Baud, 8 bits no parity.

Using

The device can be used with any other device that has a serial interface, for experimentation it can be connected to a USB to Serial device and commands entered directly at the keypad.

** NOTE BV518

NOTE: TX<>RX and RX<>TX. Any serial software will do but because but BvSerial should be used as this will allow use with the Advanced topic below. For Windows this is a stand alone exe file, it does not need installing, just unzip to a directory and double click the exe.

(Sign on will be similar to this but not exactly the same)

At the prompt, commands can be entered, for example dir to see the contents of the SD Card. As an example do the following:

  • fiNew(80,"test")
  • fiPut(5,"This is text stored at index at 5")
  • fiPut(12,"12.773") // number as text
  • fiGet(5)
  • fiGet(12)

The software can even be added and updated, see the advanced topic below for details on that.

Aduino

There is no need for a library as this is a simple serial device. Any microcontroller or other device will do provided it can send out serial information

The above sketch uses soft serial running at the default of 115200 so any 2 pins will do. The scenario is a data logger with four sensors. To make the sketch as simple as possible no actual sensors are used. If the sketch is run then 2 files are created on the SD Card:

SENS1.TXT
SENS.CSV

If the csv file is put in a spread sheet the following comes out:

This makes it very easy to carry out data logging tasks.

Commands

The mass storage system allows one file to be open at once. There are three ways of storing and retrieving information to suit the application best. All commands are text based and will store and retrieve text. As this is a serial device binary would be difficult to handle and so for storing numbers the host can easily convert back and forth,

There are three sets of commands.

  • Line: allow reading and writing of line data. (fl)
  • Index: lines are indexed by number and can be updated (fi)
  • Two dimensional array (fa)

Command Summary

Command Description
Line commands, prefixed with fl
flNew("filename") Creates a new file
flUse("filename") Uses an existing file
flLines() Returns the number of lines in the file
flAdd("value") Adds a string to the end of the file
flGet(line) Returns the line with the given line number
Indexed Commands
fiNew(length,"filename") Creates anew indexed file
fUse("filename") Opens an existing indexed file for use
fiPut(index,"value") Stores the string at the given index
fiGet(index) Returns the string at the given index
Array
faNew(col,length,"filename") Create a new array storage
fUse("filename") Opens an existing indexed file for use
faPut(row,col,"value") Puts the value to a specified cell
faGet(row,col) Returns the value at the cell
Applies to All
fClose() Closes all open files, only needed in special circumstances
fConvert(infile,outfile) Converts a file for ease of use with other systems.

Line Storage

This type is the simplest form of storage. It is intended for when the file is orientated by lines, as in a book or configuration file. Each line is separated by CR or LF. The data in the file cannot be updated but it can be added to. This would mostly be used for existing files created by other systems.

Creates a new file for writing lines to, care any existing file will be deleted.

Opens an existing file,but if it does not exist creates an empty file. An index is also created at the same time to keep track of the lines. A lines are separated from each other by CR or LF

This will return the number of lines in the open file, including blank lines. Lines begin at zero and so the last line is flLines() - 1

Adds the string "value" to the end of the file.

Gets the string at the specified line number, the first line is 0

Indexed Storage

This is similar to line storage except that the individual records can be updated. The file must be created on the device as the indexing is at the front of the file. The actual length of the file is only limited by the SD card but when creating the file the length of the record must beset.

This is sometimes known as random access.

  • fiNew(length,"filename")

Creates a new indexed file. The length is the size of the record not of the file. Set this to the biggest individual item to store. If for example you wanted to store up to 10 digit numbers then set the length to say 15 (to give some margin). If you wanted to store random sentences then set to the maximum size of a sentence (in bytes or characters), say 500. The size cannot be altered once created.

Opens an existing file for use. The file must have been created first with either fiNew or faNew. This is the same for indexed and array storage.

Stores the "string" to the given index. The index can be any numeric value, the larger the value the greater the file size.

Returns information stored at the given index

Array Storage

This will give a two dimensional array like a spreadsheet. Each cell can be modified randomly.

Creates a new 2 dimensional array storage, the number of columns and the width of the column must be specified but the number of rows will only be limited by the size of the storage.

Puts the "value" string at the specified cell given by row and column. The table will expand to accommodate the number of rows.

Returns a value at the given cell specified by the row and column.

Both

Opens an existing file for use. The file must have been created first with either fiNew or faNew. This is the same for indexed and array storage.

Applies to indexed and file array type files both of these can be read by other systems but are padded with spaces and also have a 100 byte header. To make it easier for other systems to read the file this function is used. For an indexed file a CR LF is applied to the end of each string, for an array type file each column is separated by a ',' and each row by CR LF. If the file is named .csv then this can be directly read by a spread sheet.

Advanced

The device has been specifically designed to work with other microcontrollers to off load the burden of storage. However it is a powerful microcontroller in its own right. The following topics deal with re-establishing the device software and adding your own commands and functions.

For background information the firmware is written in ByPic and this can be modified and added to by you the user simply by writing functions.

Re Establishing Factory Firmware

The behavior of the device can be changed by writing or modifying the existing software. This may go wrong so it is possible to clear changes and start again, this only takes a few moments.

Method 1

1) In BvSerial type fclear(0), power down.

2) Download this zip file and place the 4 files on an SD Card, place the card in the device and power up.

Changing the Baud rate

Simple

By default the Baud rate is set to 115200. The serial port is UART2 (COM2) and so to change this at start up we need to close that port and re-open it.

Create a text file called main.bas and put this in it:

function main()
    comclose(2)
    wait(100)
    comopen(2,9600,512) // port,baud_rate,buffer_size
endf

Save this file to the SD card that you will be using, it will initially start at 115200, run the main function and then switch to 9600. With this method the main.bas will be needed on the SD card for it to work.

More complex

1) Download this zip file and extract to a folder

2) use BVSerial to communicate with the device.

3) REMOVE THE SD CARD

4) type flclear(0)

5) type .bl (dot bl) to invoke the boot loader and upgrade the system with the .bin file in the zip

The upgrade should increase the last digits of the serial number to be about 100

6) put the 4 files on the SD Card

7) Place the SD card back in the device and reset

The error is just a warning so can be ignored. In the above screen shot the Baud rate is changed to 9600 using the .baud command.

The device will be permanently set to 9600 with or without the SD Card. To change it back to 115200, use .bl again and re-instate the system.

As a matter of interest there is only a slight change to the file_io.bas file.

Line 29 has been removed (commented out) and the constant SYS_COMBAUD at line 30 has been added. When this file is saved to flash, which it is automatically when using the SD Card for the first time, it changes the default Baud rate.

Extra IO

The back of the board contains pads that can be used for general purpose I/O. The pins also have alternate uses that are listed below. Pins can also be used for I2C, SPI and other functions such as PWM. These can be mapped to various pin options.

  • A0 GPIO, AN0 (analog to digital 10 bit input)
  • A1 GPIO, AN1
  • B0 GPIO, AN2
  • B1 GPIO, AN3
  • GND
  • B2 GPIO, AN4, SDA2
  • A4 GPIO, SOCI
  • B4 GPIO, SOCO
  • B5 GPIO 5V tolerant - MOSI for SD Card
  • V+ Power in same as serial V+
  •  
  • 3V3 Output from Voltage regulator
  • VI See text
  • B9 GPIO, SDA 5V tolerant
  • B8 GPIO, SCL 5V tolerant
  • GND
  • B12 GPIO, AN12
  • B13 GPIO, AN11
  • B14 GPIO, AN10, SCK1 - CS for SD Card
  • B15 GPIO, AN9, SCK2 - SPI Clock for SD Card
  • B3 GPIO, AN5, SCL1

RB7 is connected to the Card detect and can be used to detect when an SD card has been inserted or removed form the socket.

VI is connected to 2 pull up resistors and if the I2C interface is used can be connected to either 3.3V or V+

For details on how to program the device see the ByPic programming language.

History

  • Released March 2016