Trouble Porting Arduino code for LSM303
CountMurphy
Posts: 19
So I recently bought a LSM303 tilt compasated compass (https://www.sparkfun.com/products/10703 ). I was originally hopeing it would be a simple serial interface that I could just read the headings off of. The chip however uses I2C. The site also contains sample Arduino code (http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/LSM303_Example.zip ). Now I've never worked with I2C, but I begain to port that code over to spin, but I am having trouble just reading values off the chip. Could someone more experianced in spin and I2C look at my code and give me a few pointers? Or if someone knows of an already built object for the chip that would be helpful too. Thanks in advance. Hopefully my code isn't that far off.
Edit: the data ready pin on the chip is going high, so I think its initalized ok. I just cant read it
Edit: the data ready pin on the chip is going high, so I think its initalized ok. I just cant read it
spin
3K
Comments
For spin's i2c object I have no idea how to translate it. The docs in the i2c object suggested something like but when I try it I get a compile error because I didn't send a data varable with it.
I'm beyond confused and would really appreciate some help.
But I'm not sure what the payload would be. The code quoted above seems to open a connection to the magnetometer and sends it a register, then closes the connection. There is no data packet. After it writes, it attempts to read. could all those lines be summed up with this?
Thats my confusion. I'm not sure if the beginTransmit and the send are part of the i2c.ReadByte code, or its something else.
Ok, I'm going to assume that ReadByte is the correct code. I'm going to use the accelerometer code as more of a guide. I will get this working eventually. Thanks for your patience. I know these are really noobish questions. And yeah, the code did work on the arduino. One step closer.....