Wireless Serial Data Link

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Wireless Serial Data Link

Post by Benj »

With the release of our new E-blocks Easy Bluetooth bundle we thought it would be a good idea to publish an article that showed off exactly what was possible when integrating a system such as Bluetooth into your embedded designs.

The user manual that is packaged with the bundle is available from the following link as are the example files. The manual explains the procedure of how to setup up the Bluetooth module using the Flowcode Bluetooth component. The manual also explains how to setup default pair keys and how to pair the module with your version of Windows.

http://www.matrixmultimedia.com/lc_bundle_manuals.php

The first example is a basic program that simply sets up your Bluetooth module into a state that allows it to be discovered and allows us to connect to it at any time. The module is given a pairing key so that no unauthorized users can connect to the module and cause problems in the system.

http://www.matrixmultimedia.com/Learnin ... /EB980.zip

With the Bluetooth module setup correctly we can now create new programs using Flowcode that simply use a standard RS232 component rather than the Bluetooth component. Therefore using the Bluetooth module as if it were a pair of copper cables rather than an intelligent wireless module. When we activate the assigned COM port on the PC, the module will automatically pair itself to the PC and then be ready for data transfer.

The last example from the Bluetooth bundle shows how to switch on and off peripherals such as relays by typing specific keys on your computer keyboard. By using a programming tool such as visual basic it would be possible to automate these commands to go out on specific events such as a certain time of day or on a web page request etc.

When working with robotics it is normally quite nice to be able to reprogram and interrogate the device without having to repeatedly connect and disconnect the device. The Bluetooth module allows us to do this with ease and “bootloader” software allows us to integrate Flowcode so that with the press of the compile to chip button the programmer is called and the program is sent.

As the system is basically using the Bluetooth module as a transparent RS232 serial connection we can do anything with this that we can with a normal serial device. This includes the usage of serial bootloaders to program our devices. If you are new to bootloaders then they are essentially a small bit of code that sits at the start of the device memory and gets executed when the device starts up. The bootloader code will wait a short while for a request from the PC. If the request is not received then the bootloader code will exit and your program will be started. If the request is received then the bootloader will start overwriting your existing program on the device with data from the serial connection. When the write process is complete the bootloader will check that the data is correct and then start up the new program.

A good serial based bootloader for PIC is available from the following link though similar bootloaders are available for AVR and ARM based devices.

http://www.etc.ugal.ro/cchiculita/softw ... loader.htm

The bootloader software allows command line parameters so it means that Flowcode can automatically call the software and dictate a source hex file. The Flowcode “Chip -> Compiler Options” programmer parameters would look something similar to this.

Programmer Location – PathToTinyBootloader.exe
Programmer Parameters - %f.hex

At the moment we would have to click compile to chip in Flowcode and then go and reset the remote device for the bootloader to startup and wait for the data from the PC. To get around this the Tiny bootloader also allows you to pre-send a byte before the bootloader re-programming process kicks in. What this allows you to do is to detect this incoming byte in your program and software reset the device if it is received. On resetting the device the bootloader code will be loaded which will reprogram the system as normal.

Software Reset Example download
Bootloader_Reset_Example.fcf
(5.5 KiB) Downloaded 553 times
By using different reset commands you could connect up a whole host of different devices and individually reprogram them as desired directly from Flowcode using the wireless connection.

User avatar
tanlipseong
Posts: 31
Joined: Thu Aug 27, 2009 3:11 pm
Location: Malaysia
Contact:

Re: Wireless Serial Data Link

Post by tanlipseong »

Benj,

I am using V3 and have duplicated your example in V3, so far it work untill software reset part, it just hang the PIC (16F887) without resetting it,
below is the C Code content from your example: -

intcon=0; //Disable Interrupts
option_reg=8; //Enable watchdog timer with 1:1 prescale
while(1); //Wait forever for watchdog reset

Please help.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Wireless Serial Data Link

Post by Benj »

Hello,

It looks like for the 16F887 devices you also need to add this line before the while instruction to activate the watchdog in software.

wdtcon = 1; //Start watchdog timer running - 1:32 Prescale

User avatar
tanlipseong
Posts: 31
Joined: Thu Aug 27, 2009 3:11 pm
Location: Malaysia
Contact:

Re: Wireless Serial Data Link

Post by tanlipseong »

TQ, it can reset now.

Post Reply