CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

External ram CY62256LL-70PC read/write example

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vibrasys



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

External ram CY62256LL-70PC read/write example
PostPosted: Fri May 26, 2006 5:29 am     Reply with quote

Hello there.
I tried to hook up a 62256 (CY62256LL-70PC),32kx8 ram chip through 2 latch chips,74hct373 on port D of a pic18F452 at 20mhz for addressing,port which is also shared for ram data i/o...seems i have a a bug in the code and can't figure it out.I get the same value when i read from both 0x105 and 0x106 address,and that is char 'A'.
Thank you in advance
here is the code

#include <18F452.h>
#device adc=8

#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads

#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

#define EnC_H PIN_B0 // Enable Control H address
#define EnC_L PIN_B1 // Enable Control L address
#define WE PIN_B4 // Write Enable
#define OE PIN_B3 // Output Enable
#define CS PIN_B2 // Chip select
#define Latch output_low
#define Release output_high

int16 init_address;
int8 adH, adL;
int8 data_inp, data_out=0;


void Write_61256(int16 address, int8 Data)
{
adH = make8(address,1);
adL = make8(address,0);


Latch(EnC_L);
output_d(adL);
Release(EnC_L);

Latch(EnC_H);
output_d(adH);
Release(EnC_H);
// delay_us(10);

output_low(CS);
output_low(WE);
output_d(Data);
output_high(WE);
output_high(CS);
}

int8 Read_61256(int16 address)
{
int8 data_read;

adH = make8(address,1);
adL = make8(address,0);
Latch(EnC_L);
output_d(adL);
Release(EnC_L);

Latch(EnC_H);
output_d(adH);
Release(EnC_H);

set_tris_d(0x00);
output_low(CS);
output_low(OE);
data_read = input_d();
output_high(OE);
output_high(CS);
return(data_read);
}

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,20,16);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_oscillator(False);

release(EnC_L);
release(EnC_H);
output_high(OE);

printf("Starting...\r\n");
write_61256( 0x105, 'C' );
write_61256( 0x106, 'A' );
while(1)
{


data_out = read_61256( 0x105 );
printf("Address=0x105 char 'C' was written char=%C was read\r\n" , data_out);


data_out = read_61256( 0x106 );
printf("Address=0x106 char 'A' was written char=%C was read\r\n" , data_out);

delay_ms(100);

}
}
Ttelmah
Guest







PostPosted: Fri May 26, 2006 6:01 am     Reply with quote

The latch logic, appears wrong. If I remember right, the 373, is a transparent latch, with the output following the input, so long as the control input is high, and latching the input, when the signal drops. This is different from a 374, which is edge triggered on the rising edge of the control signal. Double check this logic.

Best Wishes
vibrasys



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

PostPosted: Sat May 27, 2006 5:23 am     Reply with quote

Hmm..
Here's what i had in mind for the write sequence:
- enable latch Low address
- place address adL on bus
- disable latch Low address
- enable latch High address
- place address adH on bus
- disable latch High address
- cs ram low
- wr ram low
- byte on ram i/o databus
- wr high
- cs high
And for the read sequence:
- enable latch Low address
- place address adL on bus
- disable latch Low address
- enable latch High address
- place address adH on bus
- disable latch High address
- port input mode
- cs ram low
- rd ram low
- read databus
- rd ram high
- cs ram high

you said "The latch logic, appears wrong." Can you suggest where i went wrong and how it should be?i've seen in the datasheet of pic18F8722,page 103 the use of transparent latch 373 for mem addressing.

Anyway thankx a lot Ttelmah for replyin'.....and go easy on a newbie dude ;) Laughing
regards
vibrasys



Joined: 20 Nov 2005
Posts: 16
Location: the Netherlands

View user's profile Send private message

PostPosted: Sat May 27, 2006 7:17 am     Reply with quote

Ttelmah wrote:
The latch logic, appears wrong. If I remember right, the 373, is a transparent latch, with the output following the input, so long as the control input is high, and latching the input, when the signal drops. This is different from a 374, which is edge triggered on the rising edge of the control signal. Double check this logic.

Best Wishes


Me again...you were right.I managed to get it working.It was all about latch logic.I changed to :
#define Latch output_high
#define Release output_low
and voila....hihihih Wink

Best Regards
Ttelmah
Guest







PostPosted: Sat May 27, 2006 7:33 am     Reply with quote

Well done.
Sorry I didn't reply to the earlier 'come back', I was out. However the result was 'good' in the end. :-)

Best Wishes
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Thu Oct 16, 2008 7:20 am     Reply with quote

Hello everybody,

I know this topic is quite old, but I am currently using a PIC16F84A with this CY62256LL Ram, I used vibrasys code, but I don't use any latch.

First problem, the code gives me nothing, I can't seem to be able to write or read to the chip.

Furthermore, I don't receive anything on my hyperterminal with the RS232, but the settings are good.

Could someone be of any assistance ? It would be greatly appreciated.
Thank you very much.

Code:

#include <16F84A.h>

#FUSES NOWDT          // No Watch Dog Timer
#FUSES HS             // High speed Osc (> 4mhz)
#FUSES NOPROTECT      // Code not protected from reading

#use delay(clock=20000000)   // quartz 20 MHz
#use rs232(baud=115200,parity=N,xmit=PIN_A2,bits=8,errors)

#define WE PIN_A0       // Write Enable
#define OE PIN_A1       // Output Enable
#define CE PIN_A3       // Chip select

int8 adH, adL;
int8 data_out=0;

void Write_CY62256LL(int16 address, int8 Data)
{
   adH = make8(address,1);
   adL = make8(address,0);

   SET_TRIS_B(0x00);   

   OUTPUT_B(adL);
   OUTPUT_B(adH);

   OUTPUT_LOW(CE);
   OUTPUT_LOW(WE);
   OUTPUT_B(Data);
   OUTPUT_HIGH(WE);
   OUTPUT_HIGH(CE);
}

int8 Read_CY62256LL(int16 address)
{
   int8 data_read;
   
   adH = make8(address,1);
   adL = make8(address,0);
   
   OUTPUT_B(adL);
   OUTPUT_B(adH);
      
   SET_TRIS_B(0xFF);
   OUTPUT_LOW(CE);
   OUTPUT_LOW(OE);
   data_read = INPUT_B();
   OUTPUT_HIGH(OE);
   OUTPUT_HIGH(CE);
   return(data_read);
}

void main()
{
   OUTPUT_HIGH(OE);   
   printf("Starting...\r\n");
   write_CY62256LL(0x00,'A');
   while(1)
   {
      data_out = read_CY62256LL(0x00);
      printf("Adresse=0x00 char='A' ecrit, char=%C lu\r\n", data_out);
      delay_ms(100);
   }
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Oct 16, 2008 5:46 pm     Reply with quote

Code:
   OUTPUT_B(adL);
   OUTPUT_B(adH);
I don't know the CY62256LL but without looking at the datasheet I can tell you this is wrong.
How should the external device know you have written data to the PortB and that this data is now valid for processing? You will have to provide some kind of 'clock' signal to the external device. For example, you do this when sending the Data byte.

Quote:
but I don't use any latch.
Can you provide more details about your circuit? The CY62256LL has 15 address inputs and 8 data outputs. I'm very curious how you have this connected to the 8 bits portB and still expect it to work.
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 2:46 am     Reply with quote

ckielstra wrote:
I don't know the CY62256LL but without looking at the datasheet I can tell you this is wrong. How should the external device know you have written data to the PortB and that this data is now valid for processing?

I know it bugs me too Smile.

My circuit is just a PIC16F84A and a CY62255LL linked together. The port B of the PIC is linked to the 8 bit data I/O of the memory. I hard coded the 15 bits of address (all soldered to gnd which make @0x00).

Thanks for your help.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 6:38 am     Reply with quote

magestik wrote:
I hard coded the 15 bits of address (all soldered to gnd which make @0x00).
So effectively you reduced the 32kbyte chip to a 1 byte RAM chip. This makes no sense, but nonetheless it should still work.

What is your compiler version number? This is a number like 4.081 and it can be found at the top of the *.lst file.

Quote:
Furthermore, I don't receive anything on my hyperterminal with the RS232, but the settings are good.
This is the first problem that should be fixed, if you don't receive data how do you know the RAM is not working?
If you create a simple test program for blinking a LED, does that work?
The LED is blinking at the expected rate?
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 10:48 am     Reply with quote

I've never delt with ram chip before. So the address is for where you want to write in the chip ? I thought it was THE address of the chip, like with I2C where you send the adress of the peripheral prior to data, here it would have been 0x00.
I get it now, the 15 bits of address need to be linked to the pic also.

I don't have the software here I can't tell you the version number for now.

For a simple program, i did try something like :

Code:

while(1)
{
output_b(0x00);
delay_ms(100);
output_b(0xFF);
delay_ms(100);
}


It worked at the wanted rate, i can see the signals changing.

I know what does not work is the read / write in the chip, but i'm a bit lost to why it won't :(

According to the datasheet, it well says to send the address, then the commands (CE, OE, etc...) then the data.

Hummm, so that is why the 2 latchs are needed ? so you can send (lets say) port B to the data bus, or the address bus ?
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Oct 18, 2008 11:17 am     Reply with quote

According to the data sheet you must have CE LOW, OE and WE HIGH.

Next set the desired address on the address lines, assert the data on
the I/O pins then pulse WE low to write the data to the selected address.
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Sun Oct 19, 2008 4:56 am     Reply with quote

I'll try with that order tomorrow Smile

But just the "printf" should print something on the hyperterminal. I just added a max232 to the serial output of the pic to display onto the computer. The baud rate and options are equal on both sides, yet nothing is printed :(.
magestik



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

PostPosted: Mon Oct 20, 2008 3:44 am     Reply with quote

Well i added some verification code :

Code:

void main()
{
   OUTPUT_HIGH(OE);   
   write_CY62256LL(0x00,'A');
   while(1)
   {
      data_out = read_CY62256LL(0x00);
      printf("Adresse=0x00 char='A' ecrit, char=%C lu\r\n", data_out);
      delay_ms(100);
      if(data_out=='A')
      {
         output_low(pin_b4);
         delay_ms(550);
         output_high(pin_b4);
         delay_ms(250);
         output_low(pin_b4);
         delay_ms(300);
         output_high(pin_b4);
         delay_ms(400);
      }
   }
}


With this commands on PIN_B4, i can see if data_out contains 'A'.
It seems it does contain char 'A' because the if condition is true.

So the problem seems to be with the hyperterminal Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group