View previous topic :: View next topic |
Author |
Message |
colortech
Joined: 11 Feb 2004 Posts: 2
|
SPI interface to the new At45db081b |
Posted: Wed Feb 11, 2004 2:47 am |
|
|
I am have a problem interfacing to the new at45db081b chip from atmel, I seem to be 1bit out in the return string, any pointers
Many thanks
Gary |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Feb 11, 2004 1:34 pm |
|
|
Does the chip clock on the low to high or the high to low? |
|
|
colortech
Joined: 11 Feb 2004 Posts: 2
|
|
Posted: Wed Feb 11, 2004 6:31 pm |
|
|
The chip clocks High to Low |
|
|
Guest
|
|
Posted: Thu Feb 12, 2004 6:35 am |
|
|
Hello,
I use a " AT45DB321B " with the port spi of the PIC18F452
//----------------------------------------------------------------------------
// DataFlash AT45DB321B Hardware SPI Test
//
#include <18F452.h>
#device adc=8
#use delay(clock=40000000)
#fuses H4,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
//----------------------------------------------------------------------------
// DTF_PINS Setting
//
#define DTF_CLK PIN_C3 // DTF Pin Clock
#define DTF_SO PIN_C4 // DTF Pin Sortie SPI de la DataFlash
#define DTF_SI PIN_C5 // DTF Pin Entree SPI de la DataFlash
#define DTF_READY PIN_E1 // DTF Pin Ready
#define DTF_CS PIN_E2 // DTF Pin Chip select
//----------------------------------------------------------------------------
// DTF MACRO
//
#define DTF_SELECT() output_low(DTF_CS)
#define DTF_UNSELECT() output_high(DTF_CS)
#define DTF_IS_READY() (input(DTF_READY))
//----------------------------------------------------------------------------
// TRIS
//
#define TRIS_E 0b00000010 // Tris du port E
#define TRIS_C 0b10010110 // Tris du port C
//----------------------------------------------------------------------------
// Fast IO
//
#USE fast_io(E)
#USE fast_io(C)
//----------------------------------------------------------------------------
void DTFInit()
{
output_high(DTF_CS);
output_high(DTF_CLK);
output_low(DTF_SI);
}
//----------------------------------------------------------------------------
BYTE DTF_ReadStatus()
{
BYTE Status;
//--- Select
DTF_SELECT();
//--- Command Read Status
spi_write(0x57);
//--- Status Result
Status = spi_read(0);
//--- Unselect
DTF_UNSELECT();
return (Status);
}
//----------------------------------------------------------------------------
void HwInit()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//--- Hardware SPI Setup
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4|SPI_SAMPLE_AT_END);
//--- Tris port E
set_tris_e(TRIS_E);
//--- Tris port C
set_tris_c(TRIS_C);
//--- DataFlash Initialisation
DTFInit();
//--- Interrupts ON
enable_interrupts(global);
}
//----------------------------------------------------------------------------
void main()
{
//--- Initialisation
HwInit();
printf("TDF_Test...\r\n");
while(1) {
if (kbhit()) {
switch (getc()) {
case 't'://Test bit DTF_Ready
if (DTF_IS_READY())
printf("DTF_READY\r\n");
else
printf("DTF_NOT_READY\r\n");
break;
case 's':// Status
printf("Status :%x\r\n",DTF_ReadStatus());
break;
}// End Switch
}// End IF
}// End IF
}
//---------------------------------------------------------------------------- |
|
|
Guest
|
|
Posted: Fri Feb 13, 2004 11:22 am |
|
|
Thank You |
|
|
Charlie U
Joined: 09 Sep 2003 Posts: 183 Location: Somewhere under water in the Great Lakes
|
|
|
|