SimpleIDE, Propeller Mini, and EEPROM RD/WR
Hello Everyone (Yes, I am still alive, just barely )
I have a Propeller Mini project in which I would like to store some data to the EEPROM, but I cannot get my test program to work, so I came seeking help
Before going further into this subject, let me just say that Parallax has three schematics for the Propeller Mini. The first two schematics show the 24LC256 from Microchip being used for the EEPROM and the latest update to the schematic shows the M24512 from STMicroelectronics being used for the EEPROM. Considering that the Propeller Mini is very hard to get at and verify, and that it was purchased June 27, 2021, I am currently assuming that the latest update to the schematic applies to me
Now that I have that out of the way, let me also add that I am no genius, especially concerning I2C devices.
As mentioned at the beginning, I simply want to store a couple of strings on the Propeller Mini EEPROM. As far as I can tell, the first 4 bits of the address should be 1010 and the remaining 3 bits should be 011, which I am sure is wrong, because I cannot get my test program to work
If I am interpreting things correctly, the last 3 bits of the address should correspond with the states of the E2, E1, and E0 pins of the EEPROM respectively. The datasheet for the M24512 states that if these pins are not connected they will be read as LOW. The latest schematic for the Mini shows the E2 pin #3 as not being connected, which led me to the sequence of 011 for the last 3 bits of the address.
In the following code, I attempt a write to the EEPROM and then I attempt to read it back, then if the read and writes match, I first turn a stepper motor in one direction and the reverse the rotation and turn it a little more. Of course, to my dismay, the stepper does not budge However, if I call the run_stepper() function before my attempted read and write, the stepper motor spins joyfully
Can someone please help me decipher what is going wrong?
For the sake of simplicity, I am posting the code I am using, but for completeness, I am also attaching a zipped project folder, the Propeller Mini schematic, and the datasheet for the M24512 EEPROM.
Any effort you may put forth into helping me resolve this issue will be greatly appreciated and thank you in advance
Note: Please disregard the last call to I2C_out
#include <stdbool.h> #include <stdint.h> #include <string.h> #include "simpletools.h" #define STEP 15 #define DIRECTION 14 #define PULSE_WIDTH (CLKFREQ / 1000000) void run_stepper(); // Local variables i2c *eeBus; //Bus ID used for EEPROM data storage int main() // Main function { eeBus = i2c_newbus(28, 29, 0); // Set up I2C bus, get bus ID // Use eeBus to write to device i2c_out(eeBus, 0b1010011, // with I2C address 0b1010000, 32768, 2, "abcdefg", 8); // send address 32768 (2 bytes) // and "abc..." data (8 bytes) while(i2c_busy(eeBus, 0b1010011)); // Wait for EEPROM to finish char testStr[] = {0, 0, 0, 0, 0, 0, 0, 0}; // Set up test string // Use eeBus to read from device i2c_in(eeBus, 0b1010011, // with I2C address 0b1010000, 32768, 2, testStr, 8); // send address 32768 (2 bytes) // data in to testStr (8 bytes) if(strcmp(testStr, "abcdefg") == 0) { run_stepper(); } i2c_out(eeBus, 0b1010000, 32768, 2, "0000000", 8); } void run_stepper() { int32_t counter; int32_t foward_pause = CLKFREQ / 6000; int32_t reverse_pause = CLKFREQ / 6000; uint16_t forward_steps = 4000; uint16_t reverse_steps = 4000; // Set DIRA as an output. DIRA |= 1 << DIRECTION; // Set up the CTRMODE of Counter A for NCO/PWM single-ended. CTRA = 4 << 26 | STEP; // Set the value to be added to PHSA with every clock cycle. FRQA = 1; // Set DIRA as an output. DIRA |= 1 << STEP; // Set the OUTA register to match the desired direction of rotation. OUTA |= 1 << DIRECTION; // Get the current System Counter value. counter = CNT; // Run the stepper motor at the current speed for a predetermined amount of steps while(forward_steps != 0) { // Send out a high pulse on the step pin for the desired duration. PHSA = -PULSE_WIDTH; // Wait for a specified period of time before sending another // high pulse to the step pin. waitcnt(counter += foward_pause); // Decrement running_steps forward_steps--; } // Set the OUTA register to match the desired direction of rotation. OUTA &= ~1 << DIRECTION; // Get the current System Counter value. counter = CNT; // Run the stepper motor at the current speed for a predetermined amount of steps while(reverse_steps != 0) { // Send out a high pulse on the step pin for the desired duration. PHSA = -PULSE_WIDTH; // Wait for a specified period of time before sending another // high pulse to the step pin. waitcnt(counter += reverse_pause); // Decrement running_steps reverse_steps--; } }
Comments
I don't wish to spoil your fun here, so the first think is that the memory on the P1 does not include a pull up pin so the i2c_newbus must be set for no pull up. i2c_newbus(28, 29, 1)
You also could use this code instead:
Mike
Thanks Mike, I will try that very shortly.
Well that definitely works. Thank you very very much Mike