This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F2812: while sending data via bluetooth then it is receiving the wrong data.

Part Number: TMS320F2812

I am using a F2812 based development board. One of my project goal is to send the ADC value to an android app via bluetooth. I am using a HC-05 bluetooth module and a 5 Volt is being applied to this module from a different 5V source. Following is the code for sending the any value via bluetooth.

#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include<stdio.h>
#include<math.h>
#include <stdlib.h>

// Prototype statements for functions found within this file.
void scia_echoback_init(void);
void scia_fifo_init(void);
void scia_xmit(char a);
void scia_msg(char *msg);
void ftoa(float n, char *res, int afterpoint);
int intToStr(int x, char str[], int d);
void reverse(char *str, int len);

// Global counts used in this example
Uint16 LoopCount;
Uint16 ErrorCount;

void main(void)
{

//Uint16 ReceivedChar;
char *msg;
char res[20];
// float n = 9.1;
//float m = 2.5;
float q = 2.51;

//char array[10];
//sprintf(array, "%d", 311);

ftoa(q,res,2); // Convert the float value into a string

InitSysCtrl();

EALLOW;
GpioMuxRegs.GPFMUX.all=0x0030; // Select GPIOs to be Scia pins
// Port F MUX - x000 0000 0011 0000
//GpioMuxRegs.GPGMUX.all=0x0030; // Select GPIOs to be Scib pins
// Port G MUX - x000 0000 0011 0000
EDIS;

DINT;

InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

LoopCount = 0;
ErrorCount = 0;

scia_fifo_init(); // Initialize the SCI FIFO
scia_echoback_init(); // Initalize SCI for echoback

for(;;)
{
msg ='\r'+'\n'+'\n'+res+'\0';
scia_msg(msg);
LoopCount++;

}

void scia_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function

SciaRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
SciaRegs.SCICCR.bit.LOOPBKENA =0;
// async mode, idle-line protocol
SciaRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
SciaRegs.SCICTL2.all =0x0003;
SciaRegs.SCICTL2.bit.TXINTENA =1;
SciaRegs.SCICTL2.bit.RXBKINTENA =1;

SciaRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
SciaRegs.SCILBAUD =0x00E7;
SciaRegs.SCICCR.bit.LOOPBKENA =0; // Enable loop back

SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}

// Transmit a character from the SCI
void scia_xmit(char a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
SciaRegs.SCITXBUF=a;

}

void scia_msg(char * msg)
{
int i;
i = 0;
while(msg[i] != '\0')
{
scia_xmit(msg[i]);
i++;

}
}

// Initalize the SCI FIFO
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;

}


// reverses a string 'str' of length 'len'
void reverse(char *str, int len)
{
int i=0, j=len-1, temp;
while (i<j)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++; j--;
}
}

// Converts a given integer x to string str[]. d is the number
// of digits required in output. If d is more than the number
// of digits in x, then 0s are added at the beginning.
int intToStr(int x, char str[], int d)
{
int i = 0;
while (x)
{
str[i++] = (x%10) + '0';
x = x/10;
}

// If number of digits required is more, then
// add 0s at the beginning
while (i < d)
str[i++] = '0';

reverse(str, i);
str[i] = '\0';
return i;
}


// Converts a floating point number to string.
void ftoa(float n, char *res, int afterpoint)
{
// Extract integer part
int ipart = (int)n;

// Extract floating part
float fpart = n - (float)ipart;

// convert integer part to string
int i = intToStr(ipart, res, 0);

// check for display option after point
if (afterpoint != 0)
{
res[i] = '.'; // add dot

// Get the value of fraction part upto given no.
// of points after dot. The third parameter is needed
// to handle cases like 233.007
fpart = fpart * pow(10, afterpoint);

intToStr((int)fpart, res + i + 1, afterpoint);
}
}

 


Now when i am trying to send the data via bluetooth then i am getting some garbage data ( please see the attached file). Am i doing something wrong in the code? what to do to receive the actual data?

  • The SCI expects 1 to be 3.3V and 0 to be 0V. Is this what is being sent by the blue tooth device?

    You may need to use an oscilloscope for this evaluation.

    Also, please make sure you can get the echoback example working with your PC as well. This will help with debugging connection and configuration.

    Regards,
    sal