Progress Report 2: MiniMed 530G - mshapiro2025/MedBreach-Capstone GitHub Wiki
Arduino Programming for Chip Manipulation
This week, I worked with Tom Claflin to start learning how to program an Arduino to manipulate a connected chip in order to perform actions like read data.
Working with the Winbond 3V serial flash memory chip
Info from Data Sheet
Look first for a way to detect the chip to ensure that the soldering is correct before actually reading from the chip. For the Winbond chip, this information is found on page 51. We are going to read the JEDEC ID.
We will use four pins: CS (Chip Select), CLK (Clock), DO (Data Out), and DI (Data In).
To start writing to the chip, we must set CS to HIGH. This indicates that CS starts high, so we should set it to HIGH in our setup function.
We also know that the chip supports speeds up to 133 MHz. Therefore, we can set our clock delay to anything below that value. We will use 250 microseconds (approximately 4000 KHz).
CS must be driven low, then the data must be sent. After the data is sent, CS must be driven high again.
Initial Setup
Initial steps must be contained in the void setup() { } function. When Arduino programming is compiled and sent to the device, it is run immediately, and looped repeatedly.
Defining Initial Values: Pins
Know what physical pin slots are being used on the Arduino, and set those pins to variables in the program with const int [pin variable name] = [pin number on board];
.
Defining Initial Values: Time Delays
Can define time delays as variables with int [delay name] = [time in seconds]
and call it with delay(delay);
. Can also change the time increment that the variable value is interpreted as with delayMilliseconds();
, delayMicroseconds();
, etc.
pinMode Function
To indicate that we are going to be manipulating the pin, use the pinMode([pin name], [input/output])
function. This will define if we want to give output to the pin or take input from it.
digitalWrite Function
After defining pins as constants, we must use the function digitalWrite([pin name], [value (ex. HIGH)])
to write to the pins. The digitalwrite
function is how the program identifies that the constants aren't just referring to integer values, but pins.
Writing Commands to the Chip
Defining the actions taken from the Arduino should be done in the void loop() { }
function.
We can't send bytes over the wire as bytes- they must be broken down into bits and sent individually as pulses (since we're working with data in its most raw form).
This requires using a for loop, where clock()
is a function written to set the clock pin.
for (int i = 7; i >= 0; i--) { digitalWrite([DO pin], (data >> i), 0x01); clock() }
Additional Notes
We will refer to pins as they are referred to on the data sheet. This means that DO (Data Out) is an INPUT pin for us, since we are receiving the data coming out of the chip into the Arduino, and vice versa for DI (Data In).