Vous êtes sur la page 1sur 9

ENTIC, Track 3, 3rd block.

Serial communications and data processing


Goal: To send the information acquired by the logomatic to a computer and process it using MATLAB Schedule: 4 weeks Task description: The workgroup should modify the logomatic firmware in order to transmit the information that is stored in the microSD to a computer. The logomatic has an output PIN through which the information from the internal memory is sent. Data acquired in the previous block of the Lab (pressure and compass measurements) should be codified in a specific way. After that, electrical features used to transmit such data should be chosen. It is recommended to follow the RS-232 standar for serial transmissions. After receiving the information in the computer, it should be processed and analyzed using a data processing tool (like MATLAB).

1.- Data Coding The datalogger acquires information from the input PINS as voltage and converts it into a digital format. This digital conversion corresponds to the operation MODE=2. This MODE should be chosen by editing th LOGCON.txt configuration file. The default value for the MODE variable is 0
MODE= 0

When modes 0 or 1 are selected, configuration file also takes into account the following parameters:
Baud = 4 Trigger Character = $ Text Frame = 100

When mode 2 is selected, the sampled values are referred to 3.3V. So, an internal value of 800 (for example) corresponds to an input voltage of: 800/1024 * 3.3 = 2.58V Data can be stored in two different ways: Binary: Data are stored in MSB format using 2 bytes. For example, value 1021 is stored as 00000011 i 11111101. Once we have all selected ports sampled we add two bytes both with value 24 (HEX). ASCII: voltage measures are stored as characters. So, if 803 is measured, we will store 3 characters, as 3 bytes: 8,0,3. Measures are separated by the HT character (horizontal tabulator; 0x09 in the ascii table). Once we have all selected ports sampled the logomatic adds two characters for new line indication. CR (Carriage Return; 0x0d in the ascii table) and LF (Line Feed; 0x0a in the ascii table). These special characters cannot be displayed using a simple editor as Worpad or Notepad. You will need a BIN-HEX editor like (Free Hex Editor Neo) to see them.

The format for the sampled data is selected in the following line of the logomatic LOGCON.txt
ASCII = Y

ASCII = Y (ascii), ASCII = N(binary) Sample frequency is also selected in the LOGCON.txt:
Frequency = 40

- Question 1: Codify in ASCII (8 bits) the following measurement: 763. - Question 2: Codify in MSB (2 bytes) the following measurement: 763. - Question 3: Determine the pressure and corresponding to that measure. Determine if this measure corresponds to the SIGNAL ON or OFF in the digital compass output.

Serial communication to the computer is done through the PIN 8, so it cannot be used for sampling. 2.- Programming the logomatic to use PIN 8 as a serial output port. The firmware of the logomatic is not prepared to send data over PIN 8. In order to reprogram the firmware of the logomatic you will have to get used to the process of compiling and reloading the firmware. Download the Logomatic-V2mod file from Atenea and descompress it into your Desktop. The directory contains three subdirectories (lib, LPCUSB, Main) and an executable file (FW.SFE) In the Main directory you will find the source code of the current version of the logomatic. The corresponding executable file is FW.SFE (firmware with extension SparkFun Electronics). To edit the source code open the main.c file with a C programming language editor (i.e. WinARM-20060606). In the WinARM directory youll find the PN subdirectory (programmers notepad 2) that contains a simple C editor (pn.exe). Open the main.c file of the logomatic firmware with this editor and compile it (Menu Tools Make All). The output of the compilation process will leave a file named FW.SFE (check the creation date to be sure it is the new compiled one). To load the Firmware in the logomatic just copy the object (FW.SFE) file to the logomatic SD card. When the logomatic disconnects from the USB plug of the computer, the firmware is automatically loaded and the copied file deleted from the SD memory card. (Check that the FW.SFE file is no longer in the SD card after loading it.) Once the new firmware is loaded the logomatic has to start logging according to the LOGCON.TXT file and sends the logged information through the PIN 8.

The sending of information through a programmed serial port is controlled by the function adaptatrama
void adaptatrama(char salida[], char entrada[], int *bitstotalesaenviar) { int i; ///Modificar el tamao de la trama a conveniencia /// *bitstotalesaenviar = 256;

for(i=0;i<32;i++) salida[i]=entrada[i]; }

//La trama a enviar es la trama leda

Modify the code of the firmware in order to send the character A through the PIN 8 instead the measured information (entrada[i]). Compile the firmware. Load the new executable file to the logomatic and execute it. Using the oscilloscope, visualize the data sent by the logomatic, through the PIN 8, in the different formats (ASCII, BINARY). Draw in your Lab notebook the wave you visualize in the oscilloscope. Determine the Voltage Levels, bit time and number of bits per character.

3.- Communications from logomatic to computer Once you have discovered how the logomatic sends the information through the PIN 8 serial output you will need to know how the computer expects the information to be sent to it. A very common way to send information to a computer through a serial communication is using RS-232 (recommended standard 232). RS-232 defines type of connectors, voltage levels, and other parameters to take into consideration when transmitting to the computer. To discover the characteristics of the protocol we will force a serial transmission over the computer RS-232 port. Discover the corresponding PORT ID (COM1, COM2,) Execute the Terminal.exe program (Notice that you have to change the file extension if it is different to .exe). Send a character using the Terminal program and visualize it in the oscilloscope Draw in your Lab notebook the wave you visualize in the oscilloscope. Determine the Voltage Levels, bit time and number of bits per character.

How can you determine that a character is starting to be sent?

4.- Adaptation of the logomatic PIN 8 output to the RS-232 standar The aim of this part of the lab is to adapt the output of the logomatic to the RS232 standard: Remember you will have to consider: 1. Voltage Levels 2. Framing 3. Connector

- Question 4: Design the circuit you need with MAXIM232C to adapt voltage levels (see MAXIM232C specs). - Question 5: Determine the changes you have to include in the logomatic firmware in order to send the RS232 proper framing. (see explaination of logomatic default mode of transmition). - Question 6: Design the connections you need to include in your underwater vehicle to connect the logomatic to the computer following the RS-232 standard.

Using the Terminal.exe program receive the measures that the logomatic are acquiring and sending through PIN8.

Explaination of logomatic default mode of transmition


The firmware of the logomatic is modified to acquire data from input ports and store them in a temporary 32 bytes buffer. Remember that in binary mode samples are 2 bytes long, and in ASCII mode, they can be 2 or 3 bytes long. Once the buffer is full, data are saved to the SD memory card. It is important to take into account that time needed to write data into the SD card should be less than time needed to fill the temporary buffer. When logomatic is shut down, all data stored in the buffer is lost. Sampled inputs are selected using the following LOGCON.txt options:
AD0.3 = N

Analog Digital inputs are named as follows:


1 = AD 0.3 2 = AD0.2 3 = AD0.1 4 = AD0.4 5 = AD 1.7 6 = AD1.6 7 = AD1.2 8 = AD1.3

For example, if PIN1 wants to be sampled, we should configure LOGCON.txt file with option: AD0.3=Y. When transfer of data to the SD is done, the modified firmware also copies the content of the temporary buffer to a 64 bytes array that will be used to send the data through the serial port. This process is done in the following function:
void adaptatrama(char salida[], char entrada[], int *bitstotalesaenviar) { int i; ///////////////////////////////////////////////////// ///Modificar el tamao de la trama a conveniencia /// ///////////////////////////////////////////////////// *bitstotalesaenviar = 256; ///////////////////////////////////////////////////// ////// Modificar la trama a conveniencia //////////// ///////////////////////////////////////////////////// for(i=0;i<32;i++) salida[i]=entrada[i]; //La trama a enviar es la misma que la trama leda }

This function can be used to adapt frame format of data to be sent through the serial port. By default, the content of the serial output will be the content of the temporary buffer salida[]= entrada[]. According the RS-232 standard, data are transmitted with an START bit and an STOP bits to detect the beginning and ending of each sent character. X X X X X X X s t a r t 8 bits de dades s X X X X X X s t t o a p r t 8 bits de dades

Size of tramatemp[] array should be modified according to the actual number of bytes they are transmitting for each 32 bytes buffer. To configure the Bit Time LOGCON.txt file includes the following line:
Velocidad de tx = 10

In the previous example, bit time is 1/10 = 100ms. Maximum rate supported by the firmware is 9999 bps, so maximum standard rate is 9600 bps. Time for transmission should be less than time for sampling (filling the tramatemp[] buffer). Function of the firmware to send data through the serial output is the following:
static void OutputFunc(void) { T1IR = 1; // reset TMR1 interrupt if (enviar==1) { bit = (tramatemp[byteleido]>>(bitsdelbyte))&1; if (bit==0) IOCLR0 = OUTPUT; if (bit==1) IOSET0 = OUTPUT; bitsdelbyte++; bitsenviados++; if(bitsdelbyte==8) { bitsdelbyte=0; byteleido++; } if(bitsenviados==bitsaenviar) { bitsdelbyte=0; bitsenviados=0; byteleido=0; enviar=0; } } else {

if (MODO232==1) IOSET0=OUTPUT; else IOCLR0=OUTPUT;

} VICVectAddr= 0;

Vous aimerez peut-être aussi