I'm currently working on a small project with a NXP PN532 NFC RFID Module V3 Kits Reader Writer.
My question is: What address and further function parameters do I need to set to read from BLE113-Port 15 (SDA) using the following method? By the way my NFC tag contains a UUID like this one:
dim nfcdatalen dim nfcUuid(37) dim nfcresult call hardware_i2c_read($38,0, 36)(nfcresult,nfcdatalen,nfcUuid(0))
I'm guessing my current method call is quite wrong, because I don't now the address value for Port 15 using a BLE113. SCL is running on Port 14.
Thanks in advance.
I'm not sure I understood, what do you mean by "address value for Port 15?"
ok I mean, what would be the first parameter for the
function? In my example I used
Is this the right address oder do I have to set a different value for that parameter to read from BLE113's port 15? (I mean the physical port labeled with a 15 on the boards side)
Thanks and regards,
Well, as you can see from the API documentation, that address is "I2C's 8-bit slave address according to the note above. Keep read/write bit (LSB) set to zero, as the firmware will set it automatically.". It has nothing to do with pins, that is your NFC IC I2C slave address.
Maybe you should read a bit about the I2C protocol first?
Ok, now I understand. Thanks for the tip reading the I2C manual first ;-)
As far as I know from the data-sheet of my NXP-board, the slave address is set to 0x48 by default. Which means the method call would be like this:
call hardware_i2c_read($48,0, 37)(nfcresult,nfcdatalen,nfcUuid(0))
The other question is: I have a buffer of
for the uuid I would like to read from my NFC tag. Is it correct to use the method call as shown int the code snippet above? Using 0 as second parameter and 37 as last? Furthermore is it right to address nfcUuid(0) as buffer for the methods response?
Nop, seems like you need to read the BGScript and API manuals as well
If your device's address is 0x48 you need to shift that one bit to the left so that the R/W bit is 0 because the API will automatically handle that bit. So 0x48 << 1 = 0x90
Then you also need to correct the return buffer, it's nfcUuid(0:nfcdatalen).
One thing I'm not sure is if the second parameter can be 0 as that would prevent it from sending a stop signal. Normally you don't send the stop signal in between a write and a read operation. I would put that as 1 to make sure that the stop condition is sent after the read operation.
Ok, so the correct form would be:
and to write the read-in value to a characteristic the call would be:
Sorry, if I'm messing things up a little bit ;-)
I've got the impression that I'm still on the wrong track.
As far as my concern goes my bg-script would simply call:
#0x48 is default I2C slave address for NXP board -> so 0x48 << 1 would be 0x90 call hardware_i2c_read($90,1,10)(nfcresult,nfcdatalen,nfcUuid(0:nfcdatalen))
Yet, I'm not receiving any data from my nfc-tag. I've attached the datasheet of my nfc-reader from NXP.
Do I have to configure anything else?
I'm a little bit stuck at the moment... Any ideas?
I checked the NXP datasheet quickly and it says:
SLV + W: write operation at PN532 address (0x48),
SLV + R: read operation at PN532 address (0x49).
There are many different ways that vendors are specifying the I2C address in datasheets. Some include the R/W bit (the lowest bit) in the address, like the example from NXP shown above. Some other vendors specify the I2C address just as the 7-bit value, without the R/W bit.
In this case, the PN532 7-bit I2C address is 0x24. (= binary 0100100).
The write and read addresses (including R/W bit) are formed as follows:
write: 0100100 + 0 = 01001000 = 0x48
read: 0100100 + 1 = 01001001 = 0x49
EDIT: this is incorrect ->
Our stack will add the R/W bit automatically and the address that is passed to hardware_i2c_read is the 7-bit slave address. Long story short: I would change the first parameter to $24 instead of $90 and see if it works. (In other words, you need to shift right, not left)
CORRECTED: (copied from API reference manual)
"address: I2C's 8-bit slave address according to the note above. Keep read/write bit
(LSB) set to zero, as the firmware will set it automatically"
my current configuration is:
and the SDA cable is connected to BLE's P15, SCL to P14. Yet I'm not receiving any data.
Furthermore I've double checked, that the switch on the NXP-PN532 is set to I2C communication as it can be configured by setting to channel switches on the board.
What's still wrong with my config?
Just a wild guess: I2C bus requires that you have pull-up resistors in the SDA and SCL lines. Have you checked this? Are you using a BLE113 with an evaluation kit or do you have some custom HW you are working with?
I'm using a custom hardware configuration with a BLE113 module. Currently I'm powering my NXP-board with 3V3. At the moment I don't have any pull-up resistors in the lines. Could you please explain why I need them and where to put one/some of these?
You should be able to use internal pull-ups in the BLE113 module. Can you share your hardware.xml file?
I am not going to explain the need for pull-up resistors because there are so many excellent tutorials available online: https://www.google.fi/?gws_rd=ssl#q=i2c+basics
Read one of those articles and you will understand I2C much better.
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>
In BLE113 the I2C pull-ups are automatically enabled so this is not the problem.
I'm beginning to run out of tricks. Do you have a BLE113 evaluation kit available? You could try hooking that up to your NFC device and see if you get them communicating. Just to rule out any hardware fault or design bug in your custom HW.
You could also share your schematics and full source code. Without those there is no much we can do to further help you. If you don't want to upload them here you can of course always open a private support ticket (not a private message, but support case opened here http://www.silabs.com/support/Pages/default.aspx)
If you post the schematics and source code here there is of course the possibility that you will get help from other forum users as well (not just me and Tiago). It always helps to get an extra pair of eyes looking at the problem. The choice is up to you...
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.