-
• #2
I answered your email already so the compilation this is fixed.
However I'd be pretty much certain that the speed of JavaScript is not your problem - and I seriously doubt compilation will help you in this case.
Could you post up your code, and the messages it posts up?
-
• #3
Thanks for sorting that out, although I haven't had a chance to test yet, I will so as soon as I can.
Interesting what you say. I will do as you suggest when I'm back in the office.
My suspicions have been raised because of the intermittement nature of the reponse from the BM019 board. Anyway, I'll get an update to you soon as I am keen to sort this out.
-
• #4
Ok, great. If you used software serial (as you mention on http://forum.espruino.com/conversations/329943) it's very likely you'd be getting all kinds of intermittent communications issues, which could be what you're seeing?
Espruino's hardware serial is pretty solid - and in fact if any buffers overflow so data is lost (which would happen if Espruino wasn't processing it fast enough), it should output
FIFO_FULL
to the console so you can see something has gone wrong. -
• #5
That's interesting. I am seeing FIFO_FULL messages, though again, not consistently. Anyway, as I said I'll do some more testing, capture the output and get back to you.
-
• #6
Thanks - I think it'd help to see your code.
Sometimes if people are used to Arduino they'll write code like
while (Serial1.available()==0);
- but that doesn't play well with Espruino and could cause issues if you were trying to do something like that? The best thing is to respond to data in theSerial1.on('data',...)
handler. -
• #7
Ok, I want to see if I can get SPI to work first. I know Arduino will work with BM019 and I have ordered one, but I like the Espruino package so I want to persevere with that for now until I have exhausted all options/ideas.
-
• #8
ok - SPI should be pretty straightforward I hope, and from what I can see all the example code for the BM019 uses SPI too.
-
• #9
So, here's the problems I am having with interfacing by SPI to BM019.
Before I show the code and output here are some points of note;- The code is just for test to see if I can get consistent communications going.
- I'm sending 0x55 (85) because the BM019 documentation says this should just echo back 0x55.
- I have tried just about every permutation and combination I can think of in terms of pins high/low, implementing in different ways to make it faster etc. I've spend quite some hours on this so this is my last shot before I switch to Arduino.
- I've checked my wiring loads of times and haven't spotted anything wrong there.
- It seems odd that I sometimes get a 0x55 response, which is why I suspected a timing issue.
- The BM019 documentation says I have to do a wake-up pulse so that' what I do first.
- I am using software SPI here, but I find the same result on hardware SPI.
- The output follows the code below. Note, inconsistency of output.
If anyone has any suggestions they will be most grateful received :-)
Here's the code...
print("Setting up SPI"); var spi=new SPI(); spi.setup( { sck:D19, miso:D22, mosi:D20, mode:0, order:'msb' } ); var WAKEUP_PIN=D17; var SS_PIN=D18; var LOW=0; var HIGH=1 var d=digitalWrite; function echo(){ "compiled"; d(SS_PIN, LOW); r=spi.send(0x55,SS_PIN); d(SS_PIN, HIGH); } // Send wake upfirst after giving Espruino time to load code. d(WAKEUP_PIN, HIGH); setTimeout(function(){ setTimeout(function(){ d(WAKEUP_PIN, LOW); setTimeout(function(){ d(WAKEUP_PIN, HIGH); setTimeout(function(){ setInterval(function(){ echo(); },1000); },1000); },10); },1000); },2000);
Here's the output...
| __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v01 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate >Setting up SPI echo response: 12 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 5 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 20 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 1 echo response: 85 echo response: 85 echo response: 85 echo response: 85 echo response: 245 echo response: 255 echo response: 255 [etc. ...]
- The code is just for test to see if I can get consistent communications going.
-
• #10
I really think
compiled
is a bad idea here - execution speed really will not be your issue at all.Specifying SS_PIN for
spi.send
will automatically set it low and then high after, so you shouldn't need thed(SS_PIN, LOW);
anyway.Please could you try just:
function echo(){ var r=spi.send(0x55,SS_PIN); print("echo response:",r); }
Do you have
SS_0
pulled high? It seems that if it wasn't the chip might go into UART mode which might cause some pretty strange behaviour.HOWEVER looking at http://www.solutions-cubed.com/content/Downloads/Breakout%20Modules/DATASHEET_BM019.pdf I don't think just sending 0x55 should work anyway...
That's the command, but it looks like commands need to be wrapped up - see page 20 of that document. For example their Arduino code does:
digitalWrite(SSPin, LOW); SPI.transfer(0x00); // SPI control byte to send command to CR95HF SPI.transfer(0x04); // Send Receive CR95HF command SPI.transfer(0x03); // length of data that follows is 0 SPI.transfer(0x26); // request Flags byte SPI.transfer(0x01); // Inventory Command for ISO/IEC 15693 SPI.transfer(0x00); // mask length for inventory command digitalWrite(SSPin, HIGH);
In fact it's kind of obvious that just sending 0x55 wouldn't return the right response because data on SPI is clocked in as it is clocked out... So the data you're receiving is being sent by the device even before it has received the command.
You could try this - which is just the Arduino code that's been hastily converted to Espruino. It might work - if called after your initial setup stuff?
function Inventory_Command() { var i = 0; // step 1 send the command spi.write([0x00, // SPI control byte to send command to CR95HF 0x04, // Send Receive CR95HF command 0x03, // length of data that follows is 0 0x26, // request Flags byte 0x01, // Inventory Command for ISO/IEC 15693 0x00], SS_PIN); // mask length for inventory command // ignoring delay(1); // step 2, poll for data ready // data is ready when a read byte // has bit 3 set (ex: B'0000 1000') digitalWrite(SS_PIN, 0); // Write 3 until bit 3 is set while ((spi.send(0x03) & 0x08) != 8); digitalWrite(SS_PIN, 1); // ignoring delay(1); // step 3, read the data digitalWrite(SS_PIN, LOW); var rx = spi.send([0x02,0,0]); // SPI control byte for read var data = spi.send(new Uint8Array(rx[2])); digitalWrite(SS_PIN, HIGH); console.log("Got data", data); }
-
• #11
Thanks for getting back to me. Really appreciate your help.
Interesting points. I've tried a few of your suggestions, nonetheless happy to try again.
To answer your questions first.- I do have SS_0 pulled high.
- Yes, I think I have tried the wrapper and I think that for sending command to the tag via the NFC. But I will try that again.
- Also tried the inventory stuff, but will again, try again.
Will get back to you soon with results...
- I do have SS_0 pulled high.
-
• #12
Results...
Using this code...
function echo(){ var r=spi.send(0x55,SS_PIN); print("echo response:",r); }
Gives me this...
echo response: 6 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 0 echo response: 85 echo response: 85 echo response: 255 echo response: 255 echo response: 255 echo response: 255 echo response: 255
Tried the inventory function as written above and got lots of these (while scanning a tag)...
Got data new Uint8Array(0)
I think it might be necessary to set the NFC protocol before doing this.
Anyway, you have helped in confirming I haven't been doing anything really silly, which is really want I wanted. Fresh eyes. -
• #13
Ok, great - yes, it looks like the NFC protocol setting might be needed. The echo response stuff at least seems to follow some kind of pattern which makes me think that SPI is probably working ok.
In a way it's good that it got all the way through the
Inventory_Command
function even if it didn't return anything because it shows that bit 3 was getting set.On http://www.solutions-cubed.com/bm019/ there's http://www.solutions-cubed.com/content/Downloads/Breakout%20Modules/BM019_NFC_15693_Inventory_Arduino.zip which I was using as a base for the code I posted. Creating a function for setting the protocol based on what they did in the same way I did the inventory one should be reasonably easy.
-
• #14
I agree with what you have said. In fact I have already implemented the code you are drawing my attention to, but because it didn't work I decided to try to at least get something basic working,i.e. an echo 0x55.
I have an Arduino on order so I'll give that a try and see what turns up.
Thanks again for your help. -
• #15
Hi All,
I solved this problem in the end and got the Espruino working with the Solutions Cubed BM019 Serial to NFC Converter.
To be honest, I'm not absolutely sure what I did to fix because I started over directly converting C code from the Arduino example here, http://blog.solutions-cubed.com/near-field-communication-nfc-with-the-arduino/ to Javascript.
I think the trick was that I declared the RXBuffer as a global varaible as follows.var RXBuffer=new Uint8Array(200);
-
• #16
Testo di origine
533 / 5.000
Risultati della traduzione
Risultato di traduzione
Hi, I imagine you want to create the LimiTTer device to monitor blood sugar levels detected by Freestyle Libre, I also saw this project and would like to create it with Espruino instead of Arduino.
The MDBT42Q module should already have the NFC interface so I ask you why you want to connect the BM019?
If you managed to get it working could you share the code with me?
So far I have only used Arduino and I have never used Espruino when programming in Java so your experience would be helpful to me.
Thank you.
Mario
Hi,
I am trying to interface an Espruino MDBT42Q to a BM019 NFC reader
(http://www.solutions-cubed.com/bm019/)
but can't get it to work. I think it's because JavaScript is too slow.
I attempted to use the C compiler but get the message "Only official Espruino boards are supported..."
I bought the Espruino is good faith from Cool Components and had no reason to believe it was anything other than official.
Am I missing something here.
Thanks,
Marco