Fixed a few stupid bugs -- it's now reading data correctly.

This commit is contained in:
Doug Brown 2011-12-10 13:02:21 -08:00
parent 2bc61f41aa
commit 7db22e08af
3 changed files with 32 additions and 8 deletions

View File

@ -21,7 +21,7 @@ void ExternalMem_Init(void)
Ports_Init(); Ports_Init();
// Configure all address lines as outputs // Configure all address lines as outputs
Ports_SetAddressDDR((1UL << (HIGHEST_ADDRESS_LINE - 1)) - 1); Ports_SetAddressDDR((1UL << (HIGHEST_ADDRESS_LINE + 1)) - 1);
// Set all data lines as inputs // Set all data lines as inputs
Ports_SetDataDDR(0); Ports_SetDataDDR(0);
@ -97,6 +97,21 @@ void ExternalMem_AssertOE(void)
Ports_SetOEOut(0); Ports_SetOEOut(0);
} }
void ExternalMem_Read(uint32_t startAddress, uint32_t *buf, uint32_t len)
{
ExternalMem_AssertCS();
ExternalMem_AssertOE();
while (len--)
{
ExternalMem_SetAddress(startAddress++);
// Shouldn't need to wait here. Each clock cycle at 16 MHz is 62.5 nanoseconds, so by the time the SPI
// read has been signaled with the SPI chip, there will DEFINITELY be good data on the data bus.
// (Considering these chips will be in the 70 ns or 140 ns range, that's only a few clock cycles at most)
*buf++ = ExternalMem_ReadData();
}
}
void ExternalMem_DeassertOE(void) void ExternalMem_DeassertOE(void)
{ {
Ports_SetOEOut(1); Ports_SetOEOut(1);

View File

@ -128,8 +128,8 @@ void Ports_SetWEOut(bool data)
void Ports_SetAddressDDR(uint32_t ddr) void Ports_SetAddressDDR(uint32_t ddr)
{ {
PORTA = (ddr & 0xFF); // A0-A7 DDRA = (ddr & 0xFF); // A0-A7
PORTC = ((ddr >> 8) & 0xFF); // A8-A15 DDRC = ((ddr >> 8) & 0xFF); // A8-A15
// A16-A20 are special because they are split up...(We use PORTD pins 0, 1, 4, 5, 6) // A16-A20 are special because they are split up...(We use PORTD pins 0, 1, 4, 5, 6)
uint8_t tmp = (ddr >> 16) & 0xFF; uint8_t tmp = (ddr >> 16) & 0xFF;
@ -315,7 +315,7 @@ uint32_t Ports_ReadData(void)
{ {
uint32_t result = (uint32_t)MCP23S17_ReadPins(); uint32_t result = (uint32_t)MCP23S17_ReadPins();
// Turn on/off requested bits in the PORT register. // Grab the other two bytes...
result |= (((uint32_t)PINE) << 16); result |= (((uint32_t)PINE) << 16);
result |= (((uint32_t)PINF) << 24); result |= (((uint32_t)PINF) << 24);

View File

@ -44,15 +44,24 @@ void USBSerial_Check(void)
{ {
CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
uint32_t mem = ExternalMem_ReadData(); uint32_t mem = ExternalMem_ReadData();
char dataString[11]; char dataString[11];
sprintf(dataString, "%08lX\r\n", mem);
CDC_Device_SendString(&VirtualSerial_CDC_Interface, dataString);
sprintf(dataString, "%02X%02X%02X%02X\r\n", sprintf(dataString, "%02X%02X%02X%02X\r\n",
(mem>>24) & 0xFF, (uint8_t)(mem>>24),
(mem>>16) & 0xFF, (uint8_t)(mem>>16),
(mem>>8) & 0xFF, (uint8_t)(mem>>8),
(mem>>0) & 0xFF); (uint8_t)(mem>>0));
CDC_Device_SendString(&VirtualSerial_CDC_Interface, dataString);
sprintf(dataString, "%02X %02X %02X\r\n", DDRA, DDRC, DDRD);
CDC_Device_SendString(&VirtualSerial_CDC_Interface, dataString); CDC_Device_SendString(&VirtualSerial_CDC_Interface, dataString);
} }