Member | Action | Date |
---|---|---|
![]() |
Replied
to
BLE113 + I2C NFC
I just wanted to let you guys know, that I found a solution to the problem. First of all the main problem was, that I was confused about the BLE113 description in the BG-Script documentation. It says that the Pins for I2C communication were P14, respectively P15, but what I did was I connected them to P1_4, P1_5, which was wrong. Instead I had to use the dedicated ports for SDA and SCL. My mistake after all on this end of the problem, not a failure of the BLE113.
Furthermore I managed to communicate with my NXP-PN532 NFC reader. I had to read the datasheet in more detail to figure out the whole communication approach. So to read out the firmware of the NXP you have to use the following steps: #receive firmware version of nxp pn532 call hardware_i2c_write($48, 1, 9,"\x00\x00\xFF\x02\xFE\xD4\x02\x2A\x00")(i2cWritten) # ask module for firmware version call hardware_i2c_read($48, 1, 7)(i2cresult, i2clen, ack(0:7)) # receive ack from nfc module call hardware_i2c_read($48, 1, 14)(i2cresult, i2clen, i2cfirmwareversion(0:14)) # receive data afterwards call hardware_i2c_write($48, 1, 6, "\x00\x00\xFF\x00\xFF\x00")(i2cWritten) # send ack as all data was successfully received call attributes_write(testvalue,0,5,i2cfirmwareversion(7:5)) # forward response to gatt To communicate with the NXP you need to send your command first. After that you will receive a 7-byte ACK from the NXP, that the command was received without a problem (see 6.2.2.1 of NXP datasheet for data link level information and how to build a communication frame). Now you can read again from the module and receive the firmware as payload. The last step is to send an ACK from your site to the NXP and separate the rest of the protocol frame from the payload and send it to the GATT attribute.
Hope it helps someone with the same kind of problem using NXP modules and BG-Script powered modules.
Cheers, Florian |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
To be honest with you, I'm already over my budget concerning this project as it's a larger project with additional hardware investments in the past.
Is there another way of making sure, that I'm not missing something? I did a bit of research and it turns out that sometimes the hardware needs to be told its address, but that might not be the case, right?
Regards, Florian |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
What do you mean by hooking up a logic analyzer to the lines of the reader? Furthermore is the rest of my method call correct? |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
Ok, but unfortunately the return value is still zero although I've set the parameter to $48 for writing. Do I have to set the address to $49 for reading? Or does the stack handle that for me? |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
Thanks for the wishes but, here is the deal: I'm getting the impression, that there is a general problem with the reader communication using the bgscript stack. Because the method call: call hardware_i2c_write($24,1,9,"\x00\x00\xFF\x02\xFE\xD4\x02\x2A\x00")(i2cWritten) returns a '0' which means no bytes were written to the reader. Instead the return value has to be 9, right? I'm pretty sure I have the protocol right because the Arduino framework sends the exact message to the reader, when trying to read out the current firmeware version.
It would be great if you could have a second look into your bgscript stack and it's communication mechanism as I'm not quite sure whether the calculation of the address is handled correctly by your software stack.
Thanks in advance! |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
I tried something in the meantime. I also have an Arduino Uno for testing my NFC-reader. An guess what the PN532 library from this source (Arduino-PN532 example) works and I can read in my tag. The only problem is how to port this to BG-script.
When I look into the library itself it establishes a command process by constructing the previously mentioned command like:
i2cdata(0:1) = $00 # 00 -> 2-byte i2cdata(1:1) = $00 # 00 -> 2-byte i2cdata(2:1) = $ff # FF -> 2-byte i2cdata(3:1) = $05 # LEN -> 1-byte i2cdata(4:1) = $fc # LCS -> 1-byte checksum of 0x05 is (0xfb + 1) = 0xfc i2cdata(5:1) = $d4 # D4 -> 2-byte i2cdata(6:1) = $02 # CC -> 2-byte i2cdata(7:1) = $fc # DCS -> 1-byte i2cdata(8:1) = $00 # 00 -> 2-byte The only part which I'm not quite sure of is the LCS part. The arduino example uses ~length+1 = LCS. Which would be 0xfc if I'm not mistaken, right?
I've also attached you the source of the cpp file managing the read/write commands with the reader. I hope someone can help me with further ideas
Regards, Florian |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
Ok, I tried some configurations to achieve your suggested GetFirmwareVersion approach. Unfortunately the reader does not respond the 6-byte package which includes the firmware version. It just responds nothing.
Here is what I'm doing at the moment: i2cmode(0:1) = $d4 i2cmode(1:1) = $14 i2cmode(2:1) = $01 i2cdata(0:1) = $d4 i2cdata(1:1) = $02 call hardware_i2c_write($24, 1, 3, i2cmode(0:3))(i2cWritten) call hardware_i2c_write($24, 1, 2, i2cdata(0:2))(i2cWritten) call hardware_i2c_read($24, 1, 6)(i2cresult, i2clen, i2cdata(0:i2clen)) call attributes_write(testvalue,0,i2clen,i2cdata(0:i2clen)) As you can see I even tried to set the SAM-mode of the NFC reader which disables security authentication, so you won't need a handshake in the first place (note: it is set to "normal" mode as it's called by default, I just thought it would be a good idea to set it anyway).
Furthermore I tried to understand the command structure of the datasheets chapter 7: 00 00 FF LEN LCS D4 CC Optional Input Data DCS 00 Which parts are already covert by the read/write i2c methods of BGScript? As far as I understand your example from your last post, I only need to send the CC part, which would be 0x02 in the "GetFirmwareVersion" case. By the way the written response object of the hardware_i2c_write method returns '0'.
I'm getting the impression, that I cannot reach the reader at all. Maybe I'd have to use a different address than 0x24? |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
Ok, I'll try to keep your tipps in mind. I've separated my NFC configuration in a new, smaller, own project which you can find attached to this reply.
Thanks for looking into my code :-) |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
Thanks for the information so far. My bg-script looks like this. Please keep in mind I'm a total beginner with bg-script, so don't blame me for the coding ;-)
#declare buffer for building attribute value dim tmp(1) #variable to save handle dim batconn_handle #store battery measurement result dim batresult #declare button connection dim button1port dim button1pin dim output1port dim output1pin dim output1active dim ledport dim ledpin # device option timeouts dim iTimeout dim oTimeout dim fTimeout dim oTimeoutHandle # i2c dim nfcHandle dim nfcUuid(37) dim nfcresult dim nfcdatalen # heat plate state dim thought_state # led state dim led_state # Boot Event listener event system_boot(major, minor, patch, build, ll_version, protocol_version, hw) # set variables button1port = 0 # PORT 0 button1pin = $01 # PIN 0_0 ledport = 1 # PORT 1 ledpin = $01 # PIN 1_1 output1port = 2 # Port 2 output1pin = $01 # PIN 2_0 output1active = 0 # boolean for output 1 batconn_handle=$ff # preset battery handle oTimeoutHandle=$bb # output timeout handle nfcHandle=$cc # handle for nfc module iTimeout = 0 # preset timeouts for device options oTimeout = 0 fTimeout = 0 # initialize duty cycle of channel 1 for timer 1 aka P1_1 to fade LED later #call hardware_timer_comparator(1, 1, 6, startCycle) # enable output port PIN 2_0 call hardware_io_port_config_direction(output1port, output1pin) call hardware_io_port_write(output1port, output1pin, 0) # reset output # enable feedback port PIN 1_0 call hardware_io_port_config_direction(ledport, ledpin) call hardware_io_port_write(ledport, ledpin, 0) # reset output #Enable IO interrupts from PORT 0 PIN P0_0 on rising edge call hardware_io_port_config_irq(button1port,button1pin,0) # set bondable mode call sm_set_bondable_mode(1) #set to advertising mode call gap_set_mode(gap_general_discoverable, gap_undirected_connectable) end # connection event listener event connection_status(connection, flags, address, address_type, conn_interval, timeout, latency, bonding) # device now connected call attributes_write(testvalue,0,23,"Hier ist dein Warmband!") # start soft timer for i2c read call hardware_set_soft_timer(1500, nfcHandle, 0) end # disconnection event listener event connection_disconnected(handle, result) # set bondable mode call sm_set_bondable_mode(1) # reset battery handle batconn_handle=$ff #set to advertising mode call gap_set_mode(gap_general_discoverable, gap_undirected_connectable) # invalidate timer for i2c read call hardware_set_soft_timer(0, nfcHandle, 1) end #GPIO interrupt listener event hardware_io_port_status(delta, port, irq, state) if port = button1port then if (irq & button1pin) = button1pin then # if it is port P0_0 and is HIGH # call attributes_write(button1value,0,18,"Button 1 gedrueckt") # toggle output1 if (output1active = 0) then call attributes_write(triggerThought,0,1,"1") # trigger thought START output1active = 1 else call attributes_write(triggerThought,0,1,"0") # trigger thought STOP output1active = 0 end if end if end if end # Respond to user triggered requests of read-variables event attributes_user_read_request(connection, handle, offset, maxsize) batconn_handle=connection #start measurement, read VDD/3, 9 effective bits call hardware_adc_read(15,3,0) end # ADC event listener event hardware_adc_result(input,value) #scale value to range 0-100 #measurement range is 32768=1.15v*3=3.45V #new battery ADC measurement is 20912=2.52v #minimum battery voltage is 2.0 volts=2.0v/3.45v*32768= 18996 #20912-18996=1916 batresult=(value-18995)*100/1916 #clip to 100% if batresult>100 then batresult=100 end if if batresult<0 then batresult=0 end if tmp(0:1)=batresult if batconn_handle<$ff then #if connection handle is valid call attributes_user_read_response(batconn_handle,0,1,tmp(0:1)) batconn_handle=$ff end if # just send # tmp(0:1)=value # call attributes_user_read_response(batconn_handle, 0, 1, tmp(0:1)) end # method handles incoming write requests event attributes_value(connection, reason, handle, offset, value_len, value) if handle = triggerThought then # request for thought next, extract state thought_state = value(0:1) # reading 1 byte / 8 Bit unsigned int if thought_state = 0 then # stop emotion call hardware_io_port_write(output1port, output1pin, 0) # reset to P2_0 call hardware_set_soft_timer(0, oTimeoutHandle, 1) # invalidate timeout timer end if if thought_state = 1 then # start emotion call hardware_io_port_write(output1port, output1pin, 1) # write to P2_0 call hardware_set_soft_timer(oTimeout * 1000, oTimeoutHandle, 1) # will be executed after X seconds; end if end if if handle = triggerled then led_state = value(0:1) # reading 1 byte / 8 Bit unsigned int if led_state = 0 then # stop thought call hardware_io_port_write(ledport, ledpin, 0) # reset to P1_1 end if if led_state = 1 then # start thought call hardware_io_port_write(ledport, ledpin, 1) # write to P1_0 end if end if if handle = triggervibration then led_state = value(0:1) # reading 1 byte / 8 Bit unsigned int if led_state = 0 then # stop thought call hardware_io_port_write(ledport, ledpin, 0) # reset to P1_1 end if if led_state = 1 then # start thought call hardware_io_port_write(ledport, ledpin, 1) # write to P1_0 end if end if # set device option timeouts if handle = inputTimeout then iTimeout = value(0:1) end if if handle = outputTimeout then oTimeout = value(0:1) end if if handle = feedbackTimeout then fTimeout = value(0:1) end if end event hardware_soft_timer(handle) # if timeout was reached disable output if handle = oTimeoutHandle then call hardware_io_port_write(output1port, output1pin, 0) # reset to P2_0 end if # read nfc module if handle = nfcHandle then #0x48 is default I2C slave address for NXP board -> so 0x48 << 1 would be 0x90 call hardware_i2c_read($24,1,37)(nfcresult,nfcdatalen,nfcUuid(0:nfcdatalen)) call attributes_write(testvalue,0,nfcdatalen,nfcUuid(0:nfcdatalen)) # replace 'testvalue' with 'partneruuid' end if end The schematics is a bit of a problem because there are no digital schematics at the moment. The only thing I can tell you so far is that SDA is connected to P15, SCL to P14, GND to GND and VCC to 3V3. Any other configuration hasn't got anything to do with the NFC configuration.
And I only have my own hardware configuration available at the moment.
Thanks in advance. |
Oct 28 2017, 2:06 PM |
![]() |
Replied
to
BLE113 + I2C NFC
ok, here is my hardware.xml: <?xml version="1.0" encoding="UTF-8" ?> <hardware> <sleeposc enable="true" ppm="30" /> <usb enable="false" endpoint="api" /> <txpower power="15" bias="5" /> <script enable="true" /> <port index="0" pull="down" /> <pmux regulator_pin="7" /> </hardware> |
Oct 28 2017, 2:06 PM |