|
Forum Index : Microcontroller and PC projects : huh? what am I missing?
| Author | Message | ||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
hello forum. I have a weird problem that doesn't make sense. MM2 5.0408 (I know this is not the current version but stick with me...) I have a variable x and I slice x characters from the left of a string l$. l$=Left$(a$,x) Print Len(l$),x,l$ ' debug SPI Write x,l$ I then go to use x as the number of SPI bytes to write as a string and I can see x has sliced 15 characters but now transmuted into x+1 (as shown in the Print statement)... 15 16 hhhhhhhhhhhhhhh [461] SPI Write x,l$ Error: Insufficient data > ... with the inevitable error, because the SPI Write is expecting 16 chars but got the 15 of l$ (which is correct). I have been staring at this bit of code for 10 minutes and I can't see I am doing anything wrong, it is fairly straightforward. A$ is printable characters, L$ if the right number of characters but x has changed... how can I have sliced 15 characters correctly and moments later report the quantity as 16 not 15? Local variables, no timers firing. Now down to the 5.0408 thing... I know it isn't current but surely this sort of bug couldn't have gone all this time and not got squished? I can flash to the latest firmware and see and I can probably work around it for now, just wanted to see if anyone else can point and laugh at something obvious I have missed. |
||||
| Shadamus Newbie Joined: 26/07/2020 Location: United StatesPosts: 17 |
Add the original value of a$ to your PRINT statement so you can see what you're working with. Looks like exactly like what you'd see if x were 16, but there were only 15 characters in a$ |
||||
| Atomizer_Zero Senior Member Joined: 04/07/2020 Location: United KingdomPosts: 134 |
by MM2, I'm going to assume CMM2? if so, Im running 5.05.05b4. it worked as intended. dim a$ = "hhhhhhhhhhhhhhhh" dim l$ dim x = 16 l$ = left$(a$, x) print len(l$),x,a$ 16 16 hhhhhhhhhhhhhhhh Edited 2020-08-06 03:28 by Atomizer_Zero |
||||
| Atomizer_Zero Senior Member Joined: 04/07/2020 Location: United KingdomPosts: 134 |
And as Shadamus just said. If a$ is 15 characters, then it's still correct. Your output is as expected. |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
mm2 = MicroMiteMk2 tiddly 28pin microcontroller. Thanks for your input but you can see the problem logically... I slice X characters and get (the expected) 15, next time I use X it has magically changed to 16 I have worked around by using Len(l$) in place of X in the SPI Write and it all works so the string slice is good. |
||||
| Shadamus Newbie Joined: 26/07/2020 Location: United StatesPosts: 17 |
Had to improvise, since not enough sample code given, nor starting condition of the variables. So, you're saying you've got x set to 15, grab LEFT$(A$,X) and then use SPI WRITE, passing X, and X had been modified to be 16 before the call to SPI WRITE? I don't get any such modification running on my CMM2, but may be because I'm on 5.05.04? Can you put the PRINT statement above the potentially offending actions, along with a$, and see that X is actually changing? |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4139 |
As I see it, that's incorrect. There are only 15 chars. You ask for the leftmost 16 but there are only 15 so you get them all. That's how it should be and is. If you wanted 16 then your a$ needs to be longer. X didn't magically change or change at all. It was the wrong value for the length of your a$. John Edited 2020-08-06 06:50 by JohnS |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
The answer is simple. You are asking SPI WRITE to transmit 16 bytes but the string provided is only 15 bytes long. Thus you get the error "Insufficient data". When you used Len(l$) in place of X you were asking SPI WRITE to transmit 15 bytes with a string length of 15 bytes, so there was no error. The solution is to make sure that a$ is 16 characters or more in length. Me thinks that you have been up too late working too hard or sampling the good drop. BTW you do not need to "slice off" 16 bytes using LEFT$(). The SPI WRITE command will only take as many characters as it needs from the string supplied. It you specify 16 bytes to be transmitted it will take the first 16 characters regardless of how long the string actually is. Geoff Geoff Graham - http://geoffg.net |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
Hah! fellas, I think you have it. > dim a$ > a$="fred" > a$=left$(a$,22) > No error, so as the string is X chars long, I can slice X+N and still get the X-most chars (because that's all there is)... and of course I knew that... Must be going senile, been chasing this ghost for an hour.Told you I was missing something. cheers chaps p.s. Quick question, there is no counterpart to SPI Write x,a$ by which I mean SPI Read x,a$ - what's the thinking behind this "ommission"? I am using the array form to bulk read but that uses 2K of precious RAM (256*8) and I have to loop through the array to build up a string. Just wondering. Edited 2020-08-06 13:57 by CaptainBoing |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4139 |
I don't get what you mean. What's wrong with SPI READ? I don't see any need for such a big array but if you explain more... Maybe post the code and what it's supposed to do. John |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
Micromite User Manual Page 94 so to bulk receive 256 bytes, the only option is to set up an array and pop it in there - it works, but 256 integers is 2K. It doesn't byte stuff them - which would be of limited use anyway. What would be nice is a counterpart of SPI WRITE nbr, string$. I tried, hoping it might be un-documented but no joy.I have a very quick method of sending up to 255 bytes but receiving, while undoubtedly fast requires further processing to return a string - which removes the benefits. I wrote two routines, one grabs bytes singly and pokes them into a string then adjusts the count, the other grabs all possible 255 and then loops through the array doing the same. The SPI bus speed of 24MHz reduced any hardware "lag" to almost zero (in fact there was no perceivable difference between 10 MHz and above). Code is here if you want to play http://www.fruitoftheshed.com/MMBasic.MMBasic-code-pack-to-Read-and-Write-Winbond-Flash-Memories.ashx Edited 2020-08-06 19:45 by CaptainBoing |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |