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.

c++ algorithm for Bluetooth HC 5c

Other Parts Discussed in Thread: CONTROLSUITE

hello,

I am connecting Micro controller TMS320F2808 to My android apps developed to read data of Impedance spectrometer using Bluetooth HC 5C. I have already read program to communication between Bluetooth and Microcotroller in CCS V6.


I am new user with Texas Microcontroller. I want program to send and receive data between Bluetooth and my android app.

please help me i need to finish this project as fast as possible.

Thank you in advance.

  • Hi Bhushan,

    are you using a TI Bluetooth chip?  If so, which one?  Are you looking for something to program SPI communication between the two microcontrollers?  I would recommend checking controlsuite.

    http://www.ti.com/tool/controlsuite

    Hopefully with a little more detail on what you require, we can see that your request gets to the correct forum and team.

    Best Regards,
    Lisa

  • hello,

    No i am not using TI blutooth chip. I am using HC 5c bluetooth module, here you will find datasheet.

    ftp://imall.iteadstudio.com/BLOG/2010_07/More_Powerful_Serial_Port_Bluetooth_Module_MasterSlave.pdf

    I am using TMS320f20808 microcontroller which send data to Android Mobile (Apps which i am developing ) through this Bluetooth module HC 5c. 

    so i am looking for algorithm which will send and receive data between Bluetooth and Android mobile Bluetooth. have attached my code to communication between HC 5c and Microcontroller and now i want to extend this programm.

    #include "DSP280x_Device.h"
    #include "DSP280x_Examples.h"
    
    // Prototype statements for functions found within this file.
    void scia_loopback_init(void);
    void scia_fifo_init(void);	
    void scia_xmit(int a);
    void error(int);
    interrupt void scia_rx_isr(void);
    interrupt void scia_tx_isr(void);
    #include <SoftwareSerial.h>
    // Global counts used in this example
    Uint16 LoopCount;
    Uint16 ErrorCount; 
    
    void main(void)
    {
        Uint16 SendChar;
        Uint16 ReceivedChar;
        
    // Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
    // This function is found in the DSP280x_SysCtrl.c file.
    	InitSysCtrl();
    
    // Step 2. Select GPIO for the device or for the specific application:
    // This function is found in the DSP280x_Gpio.c file.
    // InitGpio(); skip this as this is example selects the I/O
    // for SCI-A in this file itself
       InitSciGpio();
    
    // Step 3. Initialize PIE vector table:
    // The PIE vector table is initialized with pointers to shell Interrupt 
    // Service Routines (ISR).  The shell routines are found in DSP280x_DefaultIsr.c.
    // Insert user specific ISR code in the appropriate shell ISR routine in 
    // the DSP28_DefaultIsr.c file.
    
    // Disable and clear all CPU interrupts:
    	DINT;
    	IER = 0x0000;
    	IFR = 0x0000;
    
          // Initialize Pie Control Registers To Default State:
          // This function is found in the DSP280x_PieCtrl.c file.
    	  // InitPieCtrl();  PIE is not used for this example
    
          // Initialize the PIE Vector Table To a Known State:
          // This function is found in DSP280x_PieVect.c.
          // This function populates the PIE vector table with pointers
          // to the shell ISR functions found in DSP280x_DefaultIsr.c.
    	  InitPieVectTable();  
    
          // Enable CPU and PIE interrupts
          // This example function is found in the DSP280x_PieCtrl.c file.   
          EnableInterrupts();
    	
    // Step 4. Initialize all the Device Peripherals to a known state:
    // This function is found in DSP280x_InitPeripherals.c
    // InitPeripherals(); skip this for SCI tests
    	
    // Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:
    
        LoopCount = 0;
        ErrorCount = 0;
        
        scia_fifo_init();	   // Initialize the SCI FIFO
        scia_loopback_init();  // Initalize SCI for digital loop back 
    
        // Note: Autobaud lock is not required for this example
        
        // Send a character starting with 0 
        SendChar = 0;								
    
    // Step 6. Send Characters forever starting with 0x00 and going through
    // 0xFF.  After sending each, check the recieve buffer for the correct value
    
    	for(;;)
        { 
           scia_xmit(SendChar);
           while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state
      
           // Check received character
           ReceivedChar = SciaRegs.SCIRXBUF.all;			
           if(ReceivedChar != SendChar) error(1);
    
           // Move to the next character and repeat the test
           SendChar++;
           // Limit the character to 8-bits
           SendChar &= 0x00FF;
           LoopCount++;
        }
    
    } 	
    
    
    // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:	
    
    void error(int ErrorFlag)
    {
          Uint16 Error = ErrorFlag;
          ErrorCount++;
    //    asm("     ESTOP0");  // Uncomment to stop the test here
    //    for (;;);
    
    }
    
    // Test 1,SCIA  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity 
    void scia_loopback_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,
                                       // 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    =0x0000;
        SciaRegs.SCILBAUD    =0x000F;
    	SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back  
    	SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset 
    }
    
    // Transmit a character from the SCI'
    void scia_xmit(int a)
    {
        SciaRegs.SCITXBUF=a;
    }    
    
    // Initalize the SCI FIFO
    void scia_fifo_init()										
    {
        SciaRegs.SCIFFTX.all=0xE040;
        SciaRegs.SCIFFRX.all=0x204f;
        SciaRegs.SCIFFCT.all=0x0;
        
    } 

  • Hi Bhushan,

    I've used this module during my MS research couple of years ago and if I'm not wrong it supports UART/SCI communication. All you've to do is use a level shifter circuitry for taking care of 3.3V C2000 and 5V module communication. Secondly, you can make use of SCI example code present here: http://www.ti.com/tool/sprc191

    This example will help you to send and receive data to/from bluetooth module. Rest allz you've to work on is: android app side :)

    Regards,

    Gautam

  • Hi Gautam,

    thank you for your reply,

    yes, we are using SCI communication. and i found out SCI code before, i also have posted it here.

    but this code is for the send/ receive data between bluetooth and Microcontrol. so now we dont have to extend this code to send/receive that data between bluetooth and Android mobile??.

    Regards,

    Bhushan

  • so now we dont have to extend this code to send/receive that data between bluetooth and Android mobile??.

    Exactly, sending data from mcu to bluetooth module means the same data travels upto mobile phone's bluetooth module. Most importantly while sending the data from mcu, secure connection with address of phone's bluetooth module has to be taken care of.  This can be done via AT commands for the HC series module. Here are the steps:

    1.  Establish a connection between HC and Phone's BM

    2. Start sending the data

    *Pair the 2 bluetooth modules before hand for easier connectivity.

    Regards,

    Gautam

  • hii Gautum,

    i have some questions in my mind regarding how the data should be presented, what commands should be send to BM to activate it and deactivate it, to connect with other Bluetooth.

    like suppose, If in the datasheet it says to active the BM you should send first '0x0012'
    if we dont send this comands before before sending data then  data will not be send because its not activate.

    so is it necessary to write these commands in algorithm?

     

    Bhushan

  • so is it necessary to write these commands in algorithm?

    Yes, Bhushan all the commands required to get a secured communication  line is necessary.

  • hii Gautam,

    Thank u for your reply. Could you please tell me which commands we have to write to get secured communication line for this microcontroller and bluetooth connection?

    Bhushan

  • Thank u for your reply. Could you please tell me which commands we have to write to get secured communication line for this microcontroller and bluetooth connection?

    I'm sorry Bhushan, please go through the datasheet of your bluetooth module for the above info. Here's one such kind of datasheet:
    http://www.linotux.ch/arduino/HC-0305_serial_module_AT_commamd_set_201104_revised.pdf

    Regards,

    Gautam

  • hiii,i am getting expected a decalation error at for() can any body explain.

    for(;;)
    {

    // For Transmission
    GpioDataRegs.GPADAT.bit.GPIO28 = 1; // (1) Receiver_OFF;
    // Read-modify-write occurs
    GpioDataRegs.GPADAT.bit.GPIO29 = 0; // (2) Transmitter_ON;
    // Read: Because of the delay between output to input
    // the old value of GPIO28 (zero) is read
    // Modify: Changes GPIO29 to a 0
    // Write: Writes back GPADAT with GPIO28 = 0 and GPIO29 = 0

    delay_loop();

    // For Reception
    GpioDataRegs.GPADAT.bit.GPIO28 = 0; // (3) Receiver_ON;
    GpioDataRegs.GPADAT.bit.GPIO29 = 1; // (4) Transmitter_OFF;
    delay_loop();
    }
     
        Bhushan