I am currently using the DIO and the SPI of a 7200 board for
communications with our IO board. Now how much changes in the 7400 as
compared to the 7200 board. Do I have different address locations to
use for the communications? Any changes in the speed and
configuration of the SPI lines. I'll include sample code that I use
for the 7200 board to setup and communicate.
volatile unsigned int *SSPCR0, *SSPCR1, *SSPDR, *SSPSR, *SSPCPSR,
*SSPIIR, *SSPICR;
volatile unsigned int *PEDR, *PEDDR, *PBDR, *PBDDR, *GPIOBDB;
#define SPI_SEND_BUFF_FULL ((*SSPSR & 0x2) == 0)
#define SPI_SEND_BUFF_EMPTY ((*SSPSR & 0x1) == 1)
#define SPI_READ_BUFF_FULL ((*SSPSR & 0x8) == 8)
#define SPI_READ_BUFF_EMPTY ((*SSPSR & 0x4) == 0)
#define SPI_BUSY ((*SSPSR & 0x10) == 0x10)
void SPI_SETUP(void)
{
unsigned char *start2;
int fd = open("/dev/mem", O_RDWR);
TRACE(printf("SPI_SETUP()\n"));
start2 = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0x808A0000);
// SPI registers
SSPCR0 = (unsigned int *)(start2 + 0); // Control register 0
SSPCR1 = (unsigned int *)(start2 + 4); // Control register 1
SSPDR = (unsigned int *)(start2 + 8); // Data Recieve / Data Transmit
SSPSR = (unsigned int *)(start2 + 0xc); // SPI Status Register
SSPCPSR = (unsigned int *)(start2 + 0x10); // SPI Clock Prescale
register
SSPIIR = (unsigned int *)(start2 + 0x14); // Int ID register
SSPICR = (unsigned int *)(start2 + 0x14); // Int Clr register;
close(fd);
*SSPCR1 = 0x0; // Master nothing special CLEAR SSE
*SSPCR1 = 0x10; //set SSE
*SSPCPSR = 8; // Set SPI Speed this must be even
*SSPCR0 = 0x807; // SCR = 254; DSS = 8 bit;
*SSPCR1 = 0x0; // Master nothing special CLEAR SSE
*SSPCR1 = 0x10; //set SSE
}
void DIO_SETUP(void)
{
unsigned char *start;
int fd = open("/dev/mem", O_RDWR);
TRACE(printf("DIO_SETUP()\n"));
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
fd, 0x80840000);
// DIO registers
PBDR = (unsigned int *)(start + 0x04); // port b
PBDDR = (unsigned int *)(start + 0x14); // port b direction register
PEDR = (unsigned int *)(start + 0x20); // port e data
PEDDR = (unsigned int *)(start + 0x24); // port e direction register
GPIOBDB = (unsigned int *)(start + 0xC4); // debounce on port b
*PBDDR = 0xff; // upper nibble output,
lower nibble input
*PEDDR = 0xff; // all output (just 2 bits)
*GPIOBDB = 0x01; // enable debounce on bit 0
close(fd);
}
void SPI_Send(unsigned char data)
{
while (SPI_SEND_BUFF_FULL);
CONTINUE(printf("%x-",data));
*SSPDR = data;
}
unsigned int SPI_Read(void)
{
//static unsigned char olddata = 0;
unsigned char data = *SSPDR;
//while (SPI_READ_BUFF_EMPTY); printf(".");
//DEBUG(printf("%x:",data));
//if (data!=olddata) printf("%x-",data);
//olddata = data;
return data;
}
unsigned int SPI_ReadSend(unsigned int data)
{
long liTest;
unsigned char datax;
while (SPI_SEND_BUFF_FULL);
*SSPDR = data;
datax = *SSPDR;
return datax; // Send Back data received
}
// I use the DIO to select the chip I wish to talk SPI.
void SetAddress(unsigned int address)
{
static int liAddress = 0;
int liLoop;
if (liAddress==address) return;
liAddress = address;
while (!SPI_SEND_BUFF_EMPTY);
while (SPI_BUSY);
*PBDR = (*PBDR&0xf0)|(address&0xf);
}
Art McGee
www.edionline.com
1675 nw Cornelius Pass Road
Hillsboro, Oregon 97124
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|