When i read from the serial port i get the response in the format "Read 00 00 00 " (this is because of the usb/serial conversion tool i am using) where i need actual returned values (in this case 00 00 00) i have been using the substring command coupled with the length of the returned string and some maths to do this.
readTarget(); //see what it returns String ssdata1 = myString.substring(L1 - 6); // take the last 6 bytes to clear all the response text from the usbio ie "spi read" etc data11=int(ssdata1);
where readTarget() is the serial read and L1 is the length of the read string such as below
void readTarget(){ csn(01); //chip enable/select config subroutine myPort.write("SPITX 00\n"); countdelay(5); myPort.readBytes(byteBuffer); //get bytes of data myString = new String (byteBuffer); //get values and put them into a string L1 = myString.length(); //work out length of response csn(05); }
the question is: is there a better/more reliable way of doing the same thing?
also my formatting doesnt seem to be correct as i never get consistant strings (if you have any ideas on how to solve i would be most interested) ie:
I am trying to read data from a spi RF board (non ardruino board) through a usb to serial board i borrowed off someone (it does spi/i2c etc to usb conversions and is installed as a serial port).
Will the inbuilt serial libraries cope with this or will i need to use a dedicated spi library, if so where can i find a compatible one, since there is not one listed either in the libraries section or anywhere on these forums (i did use the search function
)