1
\$\begingroup\$

I am using arduino pro mini (which contains Atmega328p AU) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I am wondering if I can use cc2541 itself for processing data in order to remove arduino from circuit, so that I can save power and money. I am quite new to electronics domain. Please suggest any ways to achieve it.

\$\endgroup\$
  • 1
    \$\begingroup\$ If you have GPIO pins available and if you can write the code, you can do that for sure. \$\endgroup\$ – Whiskeyjack Jan 2 '16 at 12:56
  • \$\begingroup\$ @Whiskeyjack, I know 'what to code' but can I upload that code to cc2541? How can I do that? \$\endgroup\$ – Perry Jan 2 '16 at 13:06
  • \$\begingroup\$ I believe you can't "custom code" HM-10. You've a specific sets of AT commands which you can send via UART / USB, and get results on the same channel. \$\endgroup\$ – dhruvvyas90 Jan 2 '16 at 13:18
  • \$\begingroup\$ Thanks @dastaan, Then how can I remove arduino from my circuit to save power? Are there any ways? \$\endgroup\$ – Perry Jan 2 '16 at 13:26
  • 1
    \$\begingroup\$ I don't know whether this HM10 module can be programmed (because it has a limited number of exposed pins), but again I am not sure. If you are concerned about power, you can always make your micro-controller sleep when not working. That will save you a lot of battery juice. If you are willing to go all out, then you can design your own custom board using CC2541 and upload your code to it. This will save lots of money if you are going for a bulk but for hobby, I won't advise you to go that way. \$\endgroup\$ – Whiskeyjack Jan 2 '16 at 13:35
6
\$\begingroup\$

TL;DR version -- if you are trying to do this for just one chip and just yourself (i.e. not a product), it's probably not worth it since you'll need to spend at least $50 for a programmer.

The CC2541 is a combination of a BLE radio and 8051 with either 256K or 128K flash, and 8K of RAM. It has 23 GPIO pins, some of which can be re-purposed as I²C, SPI, UART, and programming interface

The CC2541 comes from TI with firmware supporting HCI (Host Controller Interface), which is at a lower level interface than AT commands. Some vendors, such as HMSoft, have taken the CC2541, packaged it on a board, and provided an AT command interface on top of TI's stack. That is the HM-10 on your Shield. The HM=10 can be bought separately, for example here.

Yes you can put application code on a CC2541, and use all of its I/O capabilities for your own use. It can be re-programmed using two of the GPIO pins using a TI programmer called CC Debugger, which costs $50.

The gotcha is all of TI's documentation assumes you are using the IAR Embedded Workshop for 8051, which costs almost $3000. (IAR has a free evaluation version which is good for only 30 days.) I don't know how hard it would be to use one of the free 8051 compilers out there.

I have not used the HM-10. Instead, I have used the Silicon Labs (formerly Bluegiga) BLE113, which is another small module with a CC2541 packaged inside a shielding can plus some capacitors and an antenna and costs the same as the HM-10 ($12).

The advantage of the BLE113 (besides the fact that it is shielded and FCC certified) is that instead of programming the 8051 in C, they have provided a language called BGScript, which is a BASIC like syntax -- you can literally write a BLE application in a few dozen or so lines of code.

Here is the complete BGScript code, for a BLE wireless thermometer that sends back the temperature to a host once a second:

dim tmp(5)
dim celsius
dim offset
dim addr(6)

#init gap mod, bonding and start freerunning times on system boot
event system_boot(major ,minor ,patch ,build ,ll_version ,protocol_version ,hw )

    #Get local BT address
    call system_address_get( )(addr(0:6))

    # Write BT address to DI service serial number string
    call attributes_write(xgatt_dis_2a25,0,6,addr(0:5))

    #Set device to advertisement mode and allow undirected connections
    call gap_set_mode(gap_general_discoverable,gap_undirected_connectable)

    #Allow pairing
    call sm_set_bondable_mode(1)

    #set timer to periodically create an interrupt with interval of 1s
    call hardware_set_soft_timer(32768,0,0)
end

#timer expired
event hardware_soft_timer(handle)
    #Request for ADC reading
    call hardware_adc_read(14,3,0)
end

#ADC measurement ready
event hardware_adc_result(input,value)
    offset=-1600

    # ADC value is 12 MSB
    celsius = value / 16
    # Calculate temperature
    # ADC*V_ref/ADC_max / T_coeff + offset
    celsius = (10*celsius*1150/2047) * 10/45 + offset

    #set flags
    tmp(0:1)=0      
    #set as float
    tmp(1:4)=float(celsius, -1)

    #write the temperature information to the GATT database
    call attributes_write(xgatt_htm_2a1c,0,5,tmp(0:5))      
end

event connection_disconnected(handle,result)
    #in case if disconnect, return to advertisement mode
        call gap_set_mode(gap_general_discoverable,gap_undirected_connectable)
end

(There is also an XML file, gatt.xml that contains all of the GATT service and characteristic UUIDs etc.)

BGScript has access to all of the chip's peripherals, such as the GPIO pins, I²C, SPI and UART, and in the example above, the ADC. You don't have to buy an 8051 development environment because they give you one for BGScript for free. You still have to buy the $50 TI programmer though.

\$\endgroup\$
2
\$\begingroup\$

These days, Texas Instruments (TI) provide their Code Composer Studio (CCS) for free. It's a full-featured IDE capable of supporting a huge range of TI processors. The original poster asked a classic "open-a-can-of-worms" question which is to be commended. The reality is that a 'simple' BLE transciever is controlled by a complex System on a Chip (SoC) IC. It really is a complete computing platform on a chip with its own Real Time Operating System (RTOS) to help you get access to the features or peripherals the processor is connected to such as the RF module and any switches or sensors.

Programming an Arduino is child's play compared to programming an SoC, but then there comes a time in a developer's life when they must yet again face a mountainous learning curve in order to better themselves.

\$\endgroup\$
  • \$\begingroup\$ Unfortunately, as of today's updates, Code Composer Studio does not support the CC2541, or anything else with an 8051 CPU core. I just downloaded and updated to be certain. \$\endgroup\$ – doc hawk Nov 26 '18 at 21:24
  • 2
    \$\begingroup\$ Do you have any actual evidence that CCS supports the CC254x? Those parts originate with an acquisition and use an 8051 core rather than a TI-traditional processor core. A comment mis-posted as an answer has today alleged CCS does not support the CC2541 so could you either support your suggestion or withdraw it? \$\endgroup\$ – Chris Stratton Nov 26 '18 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.