I'm trying to code BGScript but I have some questions. Can you help me?
I have DKBLE112 which is Development Kit of the BLE112 module built around the CC254x, an 8051 derivative with an on-chip BLE transceiver. And my questions are as following.
I could to blink a LED by using an example code below. But some lines are unclear to me.
The first is below.
# setup port 2 pin 1 for the switch output
call hardware_io_port_config_direction(2,$2)
The comment say pin 1. Why $2 is pin 1? And how can I change to use P2_2?
The second question is this.
call hardware_io_port_write(2,$2,$2)
Why the setting data is $2? (I changed $1 but not blinked)
Thanks,
dim led
event system_boot(major,minor,patch,build,ll_version,protocol,hw)
call hardware_spi_transfer(0,16," Blinky Light ")
# setup port 2 pin 1 for the switch output
call hardware_io_port_config_direction(2,$2)
# turn port pin off
call hardware_io_port_write(2,$2,$0)
led = 0
call hardware_set_soft_timer(32768,0,0)
end
event connection_disconnected(handle,result)
call gap_set_mode(gap_general_discoverable,gap_undirected_connectable)
end
event hardware_soft_timer(handle)
if led > 0
call hardware_io_port_write(2,$2,$0)
led = 0
else
call hardware_io_port_write(2,$2,$2)
led = 1
end if
end
Best Answer
I've got a fair amount of BGScript experience and I have some (semi) documented example scripts here: https://github.com/sureshjoshi/ble113-firmware-examples
As a general statement, using $1 or $2 in those APIs is to get the specific PIN on a PORT. So, you're essentially doing a bitmask.
$1 is pin 0, $2 is pin 1, $4 is pin 2, etc...
If you want to access multiple pins at once, you would use the appropriate value. E.g. 3 in hex is 0x03 (or $3 in BGScript), which is also 0b00000011, which sets pin 0 and pin 1.
In the embedded world, you'll need to do a lot more of this: https://en.wikipedia.org/wiki/Mask_%28computing%29
If you look through the documentation of the device you're using, they will specify what the functions of each pin at each port are.