Somewhere in there some data should be stored in TWDR, but I am not entirely sure how to get it, or if it is done correctly. Then we must write the data, have a read acknowledgment, and then continue sending one until there is an nack, and then stop the transmission. I understand we should be initializing the SCL and SDA lines, initializing the I2C by setting the prescalers correctly and getting the clock frequency by utilizing the I2C clock equation, then starting I2C using the start condition, wait for the end of a transmission, checking for the flag, loading the address (I believe 0x52 for write and 0x53 for read for this sensor), and waiting until the flag goes down to check for the end of the transmission. The main confusion is how to just get the data from the VL53L0X. In the twi.h and the wire.h I see the registers they are calling and what bits they are assigning in some of the registers for the Arduino's, so it it somewhat clear. I have done a couple internships in design, circuit analysis, etc. I have no desire whatsoever to do embedded programming or any programming for that manner besides simple matlab coding. We are required to take two C/C++ classes and this micro controller class, but other than that there is no coding required for us. Thankfully I am an EE and this is my last coding based class at all. We have always used int main() and it appears to me that is how it should be gone about. ![]() When looking at arduino.h all I see in there is them actually creating the functions for loop and setup, and I understand that setup is just being run one time, which is why I created a function for it and ran it once in main, and use the while loop to continuously run the code that was in the void loop. of the Mega 2560 datasheet kind of lays out how to use I2C communication with conventional C code, but it is the information that is getting stored in TWDR that is kind of throwing me for a loop, and how to check what is in there. This is the first time we have used communication and have not really learned anything about it. I have looked into the 2560 datasheet kind of heavily, and have utilized it for the entire semester thus far. If you want to learn, I and other will help. If however, you just want someone to do it for you, there are several eager-beavers in the forum ready to demonstrate their expertise with the language, or at least try to convince the rest of us that they've read a book or two, and will gladly re-write the code for you. There are numerous excellent tutorials available free online. If you don't understand main() then you don't understand basic C/C++ and perhaps that's a good place to start. It's not a lot and understanding how to do it yourself will gain you much more than asking someone to lay it out for you. ![]() Start by looking at Arduino.h and wore.h and see what functionality you're being asked to reproduce on your own. If you intend to establish anything that resembles a career based on embedded programming, this is fundamental knowledge you need. If you have been instructed that you can't use the fundamental libraries that the Arduino IDE employs to hide the hardware from you, it's likely because you are being asked to think about the underlying platform as something more than an abstraction. At this point a good reference manual for C/C++, a copy of the avr-libc manual and the datasheet for the 2560 are your best friends. ![]() When you eliminate Arduino.h, setup() and loop(), you are now programming, as we say, 'bare metal'. I suspect that is the purpose of the exercise. You're just going to have to learn how to write C/C++ programs. I can use Arduino.h and comment out the serial.begin(9600) and the print statement and it will still work fine, I just can't figure out how to use int main instead of the loop. We are also not aloud to use the wire library and we have to use the specific TWI registers for the Mega 2560 but that is another problem I will figure out later.īelow is my code: the setup() function is at the bottom of the VL53L0X.cpp file and the initLED() is just initializing the LED's by assigning the appropriate pins as outputs. Below is my code, can anyone point me in the right direction. I tried using the int main() and then placing the setup() function in that, and then using a while(1) but it does not work at all. I am using the VL53L0X sensor to set up two leds, one will be on when the reading is >400mm and then the other will be on when it is less than 400mm. First of all, we are not allowed to use the arduino.h library for this project, and I have been messing around with it for hours.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |