ParkingLotLust
Member
In my DIG class we're working on interfacing a DRAM chip, specifically the **broken link removed** chip, to the dsPIC30F4011.
We quickly went over some sample code in class but not much info was given, so please forgive me if Ive overlooked something obvious.
According to the datasheet, I need to refresh 256 times every 4mS. I have set up timer1 as such and verified the timer1 interrupt occurs every 4mS.
My code tries to do the following:
- write 0xA0 to 0x1234
- read the data back
- turn on an LED if the data was read back correctly.
Right now, I read back 0x20 no matter what I try. Im sure there's a problem, I just need another set of eyes to see it.
Also, the way Ive decided to do addressing is as follows:
- 16bit address which is divided into a row and column
(this part is assumed - my teacher wouldnt give me a straight answer. I dont know if you can actually do this or not - I dont understand how many rows and columns there are)
In the attached code, Ive commented out the read/write code I tried to write from the timing diagrams in the datasheet. I also tried more logical code, which is what returns 0x20. Any advice is greatly appreciated!
We quickly went over some sample code in class but not much info was given, so please forgive me if Ive overlooked something obvious.
According to the datasheet, I need to refresh 256 times every 4mS. I have set up timer1 as such and verified the timer1 interrupt occurs every 4mS.
My code tries to do the following:
- write 0xA0 to 0x1234
- read the data back
- turn on an LED if the data was read back correctly.
Right now, I read back 0x20 no matter what I try. Im sure there's a problem, I just need another set of eyes to see it.
Also, the way Ive decided to do addressing is as follows:
- 16bit address which is divided into a row and column
(this part is assumed - my teacher wouldnt give me a straight answer. I dont know if you can actually do this or not - I dont understand how many rows and columns there are)
In the attached code, Ive commented out the read/write code I tried to write from the timing diagrams in the datasheet. I also tried more logical code, which is what returns 0x20. Any advice is greatly appreciated!
Code:
#include <p30f4011.h>
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void);
void timerInit(void);
void portInit(void);
void delayCycles(int);
unsigned char read(unsigned short);
void write(unsigned short, unsigned char);
int i; // refresh counter
unsigned char row, col;
#define CAS PORTFbits.RF0
#define RAS PORTFbits.RF1
#define OE PORTFbits.RF4
#define W PORTFbits.RF5
#define SUCCESS PORTFbits.RF6
// pin setup:
// portb - a0-a7
// porte - d0-d3
// f0 - /cas
// f1 - /ras
// f4 - /oe
// f5 - /we
// f6 - success led
int main(void)
{
portInit();
timerInit();
unsigned char data = 0xA0;
unsigned short address = 0x1234;
write(address, data);
delayCycles(2000);
TRISE = 0xFF;
unsigned char temp = read(address);
if (temp == data)
SUCCESS = 1;
while(1);
return 0;
}
void portInit()
{
// pin setup:
// portb - a0-a7
// porte - d0-d3
// f0 - /cas
// f1 - /ras
// f4 - /oe
// f5 - /we
ADPCFG = 0xFF;
TRISB = 0x00;
TRISE = 0x00;
TRISF = 0x00;
CAS = 1;
RAS = 1;
OE = 1;
W = 1;
}
void timerInit()
{
PR1 = 500; // 8uS per tick = 500 ticks
T1CON = 0; // clear t1con
T1CONbits.TCKPS = 1; // prescale 8
IFS0bits.T1IF = 0; // clear flag
IPC0bits.T1IP = 7; // high prio
IEC0bits.T1IE = 1; // enable interrupt
T1CONbits.TON = 1; // start counting
}
void _T1Interrupt(void)
{
// i should happen every ~4ms
for (i = 0; i < 256; i++)
{
CAS = 0;
//delayCycles(50);
RAS = 0;
//delayCycles(50);
CAS = 1;
//delayCycles(50);
RAS = 1;
//delayCycles(50);
}
IFS0bits.T1IF = 0;
}
void delayCycles(int cycles)
{
while (cycles-- > 0);
}
unsigned char read(unsigned short address)
{
unsigned char row = address / 8;
unsigned char col = address % 8;
unsigned char temp;
__asm__ volatile("disi #0x3FFF"); /* disable interrupts */
/*
PORTB = row;
delayCycles(50);
RAS = 0;
delayCycles(50);
W = 1;
delayCycles(50);
PORTB = col;
delayCycles(50);
CAS = 0;
delayCycles(50);
OE = 0;
delayCycles(50);
temp = PORTE;
delayCycles(50);
CAS = 1;
delayCycles(50);
OE = 1;
delayCycles(50);
RAS = 1;
delayCycles(50);
*/
PORTB = row;
delayCycles(10);
RAS = 0;
delayCycles(10);
PORTB = col;
delayCycles(10);
CAS = 0;
delayCycles(10);
TRISE = 0xFF;
delayCycles(10);
OE = 0;
delayCycles(10);
temp = PORTE;
delayCycles(10);
OE = 1;
delayCycles(10);
RAS = 1;
delayCycles(10);
CAS = 1;
delayCycles(10);
TRISE = 0x00;
__asm__ volatile("disi #0x0000"); /* enable interrupts */
return temp;
}
void write(unsigned short address, unsigned char data)
{
unsigned char row = address / 8;
unsigned char col = address % 8;
__asm__ volatile("disi #0x3FFF"); /* disable interrupts */
/*
PORTB = row;
delayCycles(50);
RAS = 0;
delayCycles(50);
W = 0;
delayCycles(50);
PORTE = data;
delayCycles(50);
PORTB = col;
delayCycles(50);
CAS = 0;
delayCycles(50);
W = 1;
delayCycles(50);
CAS = 1;
delayCycles(50);
RAS = 1;
delayCycles(50);
*/
PORTB = row;
delayCycles(10);
RAS = 0;
delayCycles(10);
PORTB = col;
delayCycles(10);
CAS = 0;
delayCycles(10);
PORTE = data;
delayCycles(10);
W = 0;
delayCycles(10);
W = 1;
delayCycles(10);
CAS = 1;
delayCycles(10);
RAS = 1;
delayCycles(10);
__asm__ volatile("disi #0x0000"); /* enable interrupts */
}