Does the parallel transmission of data work in Arduino in the following manner?
The data does not seem to get written since I can't see a change in my DDS module. Any suggestions. I already got a hold of some Serial data transfer code but it did not help me much with parallel transfer.
void setup() {
// Set the Mode of the Address and Data pins
// Address pins
pinMode(23, OUTPUT);
pinMode(25, OUTPUT);
pinMode(27, OUTPUT);
pinMode(29, OUTPUT);
pinMode(31, OUTPUT);
pinMode(33, OUTPUT);
// Data pins
pinMode(24, UTPUT);
pinMode(26, OUTPUT);
pinMode(28, OUTPUT);
pinMode(30, OUTPUT);
pinMode(32, OUTPUT);
pinMode(34, OUTPUT);
pinMode(36, OUTPUT);
pinMode(38, OUTPUT);
// Write Pin
pinMode(writePulsePin, OUTPUT);
// Read Pin
pinMode(readPulsePin, OUTPUT);
// Reset Pin
pinMode(resetPin, OUTPUT);
// Update Pin
pinMode(updatePin, OUTPUT);
//COM13 Serial between Arduino Due SAM3X and Serial Monitor.
Serial.begin(115200);
//COM9 serial between Due and DDS Control Console.
Serial1.begin(19200);
while(!Serial){};
} //end setup
loop{
setAddressAndData(Address, Data, Length, Setter)
{
if (DEBUG) Serial.println( " Set function = " + Setter);
int addLength = Length;
int dataLength = Length;
if (DEBUG) {
Serial.println(" addLength = " + String(addLength));
Serial.println(" dataLength = " + String(dataLength));
}
// since if there are 6 address bytes there will also be 6 data bytes. The
// length of the address will be equal to the the sizeof the Address.
// The number of bytes in an address will equal the size of the Address
// numBytes is same for Data as for Address
int numBytes = Length / 8;
// The code will be setting the pin direction to output. then for each bit
// in the address or Data; we will set the pin value to either 0 or 1
// depending on the pin position in the Data or Address. I did not use
// the DDR's directly for this operation since the pins were located on
// different ports which would have made iteration a nightmare and in the
// end waste even more memory.
for ( numBytes; numBytes >= 1; numBytes--)
{
// Step 1. Generate the Addresses
// The startPin values come from the board Arduiono Due from the parallel
// port consisting of bits 20 - 55 of which we use 24 - 38 all even. 23 - 33 all odd
// are the address bits, data comes from the even bits.
if (DEBUG) Serial.println(" ==> numBytes = " + String(numBytes));
int startPin = 23;
// Main loop for the Address setup
// addLength - 3 since we want to start with the 6th bit per byte
// hence 48 - 1 to get actual bit position - 2 since that there are
// only 6 bits in each address hextuplt. i.e, Instead of starting at
// bit 47, 45 is the start point and it ends at 40. 45 to 40 inclusive are
// 6 bits.
for ( int bit = addLength - 3; bit >= addLength - 8; bit--) {
//pinMode(startPin, OUTPUT);
digitalWrite(startPin, (bitRead(Address, bit)));
if (DEBUG) {
Serial.print(" ==> startPin = " + String(startPin) +" ==> bit = " + String(bit));
int value = bitRead(Address, bit);
Serial.println(" ==> The read bit value = " + String(value));
}
// do next pin
startPin += 2;
}
// Step 2. Generate the Data segments
// The startPin values come from the board Arduino Due from the parallel
// port consisting of bits 20 - 55 of which we use 23 - 41. 24 - 38 are the
// data bits. 37 is the NotWrite pin and 39 is the Read pin. The boards
// Read not and Not Write did not align with the DDS pin out that's why it was
// generated separately.
if (DEBUG) Serial.println(" ==> numBytes = " + String(numBytes));
// Main loop for the Data setup
// Data - 1 since we want to start with 47th bit hence 48 - 1 to get the
// actual bit position since there are 8 bits in each Data byte. i.e,
// Starting at bit 47, it ends at 40. 47 to 40 inclusive are 8 bits.
startPin = 24;
for ( int bit = dataLength - 1; bit >= dataLength - 8; bit--) {
//pinMode(startPin, OUTPUT);
digitalWrite(startPin, (bitRead(Data, bit)));
if (DEBUG) {
Serial.print(" ==> startPin = " + String(startPin) + " ==> bit = " + String(bit));
int value = bitRead(Data, bit);
Serial.println(" ==> The read bit value = " + String(value));
}
// do next pin
startPin += 2;
}
// Step 3. Generate NotWrite and UpdatePulse signals.
Serial.println("Write Pulse Executed");
NotWritePulse();
// Step 4. Setup for next Address byte, Data byte, and Write Command.
Address = Address << 8;
Data = Data << 8;
}
Serial.println("Update Pulse Executed");
UpdatePulse();
}// End SetAddressAndData
}//End Loop
The file attached has the printout of the order that the address and data are setup,
called Display for POST. It contains the Serial output data to screen
The first 6 bits are the Address bits A5->A0
The second 8 bits are the Data bits D7 -> D0
It did not fit any more in this POST so I had to use an Attachment, sorry.
Display for POST.txt (9.22 KB)