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

PIC18F85J90 and cypress 62167

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



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

PIC18F85J90 and cypress 62167
PostPosted: Wed Jun 11, 2014 4:38 am     Reply with quote

Hi everyone,

I am trying to write and read inside a memory cypress 62167 with a PIC18F85J90. Here is my programs for read and write in the memory and the port configurations, i precise that the I/O are on the port D, the adress bits are on the ports G, H and J (21 bits) and on the port C (C1 and C0) :
Code:

void set_port (void){

   set_tris_a(0xBC);   //CLKI in input et CLKO in output
   set_tris_h(0x00);   //port h, g et j in output
   set_tris_g(0b00000);
   set_tris_j(0x00);
   set_tris_c(0x80);   //port C in input pour RX,
                  //the rest in output(C0, C1 et TX)
}

void write(unsigned char data){

   output_high(WE);
   output_high(OE);      
   set_tris_d(0x00);   //port D in output
   output_low(WE);      
   output_d(data);      //data on the port D
   output_high(WE);
   set_tris_d(0xFF);
}

unsigned char read(void){
   unsigned char data1;
   
   output_high(WE);
   output_high(OE);
   set_tris_d(0xff);     //port D in input
   output_low(OE);      
   output_high(OE);
   data1=input_d();      //data on the port D
   
   set_tris_d(0x00);
   return data1;
}

When I use this code in order to write in different adress all the elements of the table rand (which is a table with character so 8 bits max), I can see on MPLAB that everything is perfect (on simulation) but when I run this programme on the microcontroller and turn a LED on if the data read and the data write are the same and if not I turn the LED off, I can see my LED blinking (which means that there is a difference between the both datas), here is the program :

Code:

#use delay (clock=20000000)
#use rs232 (baud=9600,XMIT=PIN_C6,RCV=PIN_C7,BITS=8,PARITY=N)
 
void main{
   set_port();

 while(1){
  for(MSB=0;MSB<127;MSB++){   
      for(LSB=0;LSB<254;LSB++){   
         if(i<200){   
            output_h(LSB);   
            output_j(MSB);
            output_g(0b00000);      
            
            write(rand[i]);   
            delay_us(50);
            test=read();   

            if(test == rand[i]){   
               output_high(LED2);      
            }else{
               output_low(LED2);
            }
            i=i+1;
         }
                  }
  }
}

I do not understand why I have that difference, can anybody help me please?

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 11, 2014 5:32 am     Reply with quote

a few of points....

1) since your program is just 'snippets' , we don't know if you're controlling the I/O pins with 'fast_io()' or letting the compiler handle it.

2) what port/pin is LED2 ?

3) 50us between write then read may be too fast,though I don't have the specs on the Cypress part.

4)use of 'random' data is bad in testing any program.

5) always add 'errors' to the use RS232(...options...).

6) if possible, add code to send the data 'written to Cypress', and 'read from Cypress' to a PC terminal program.

7) slow down the overall 'loop' to say 1 or 2 Hz for debugging purposes.

8) what 'clock' speed?

most of these deal with 'timing' issues which means reading the Cypress datasheet and confirming you're not going faster than allowed.

hth
jay
bourne



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

PostPosted: Wed Jun 11, 2014 5:43 am     Reply with quote

Hello,
Thank for your response

1) I do not use fast I/O, I have just took off the part interupt for the serial ports and how I fill the random table (which is not important for my problem).

2) LED2 is ont the pin 2 of the port B.

3) I saw in the datasheet that the times necessary for the memory and less than 50 ns so I put a time which is bigger than necessary.

4) The random table is a table that I fill myself with a special algorithm, I know what is inside (random is only a name for that table).

5) I add it in my program thanks.

8) Clock speed is the frequency that I am working at...I forgot the #fuses that i used, I add it now.
bourne



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

Re: PIC18F85J90 and cypress 62167
PostPosted: Wed Jun 11, 2014 5:44 am     Reply with quote

bourne wrote:
Hi everyone,

I am trying to write and read inside a memory cypress 62167 with a PIC18F85J90. Here is my programs for read and write in the memory and the port configurations, i precise that the I/O are on the port D, the adress bits are on the ports G, H and J (21 bits) and on the port C (C1 and C0) :

void set_port (void){

set_tris_a(0xBC); //CLKI in input et CLKO in output
set_tris_h(0x00); //port h, g et j in output
set_tris_g(0b00000);
set_tris_j(0x00);
set_tris_c(0x80); //port C in input pour RX,
//the rest in output(C0, C1 et TX)
}

void write(unsigned char data){

output_high(WE);
output_high(OE);
set_tris_d(0x00); //port D in output
output_low(WE);
output_d(data); //data on the port D
output_high(WE);
set_tris_d(0xFF);
}

unsigned char read(void){
unsigned char data1;

output_high(WE);
output_high(OE);
set_tris_d(0xff); //port D in input
output_low(OE);
output_high(OE);
data1=input_d(); //data on the port D

set_tris_d(0x00);
return data1;
}

When I use this code in order to write in different adress all the elements of the table rand (which is a table with character so 8 bits max), I can see on MPLAB that everything is perfect (on simulation) but when I run this programme on the microcontroller and turn a LED on if the data read and the data write are the same and if not I turn the LED off, I can see my LED blinking (which means that there is a difference between the both datas), here is the program :

#define LED0 PIN_B0
#define LED1 PIN_B1
#define LED2 PIN_B2
#define LED3 PIN_B3
#define LED4 PIN_B4

#define WE PIN_A0
#define OE PIN_A1


#FUSES HS //High speed oscillator
#FUSES NOWDT

#use delay (clock=20000000)
#use rs232 (baud=9600,XMIT=PIN_C6,RCV=PIN_C7,BITS=8,PARITY=N)

void main{
set_port();

while(1){
for(MSB=0;MSB<127;MSB++){
for(LSB=0;LSB<254;LSB++){
if(i<200){
output_h(LSB);
output_j(MSB);
output_g(0b00000);

write(rand[i]);
delay_us(50);
test=read();

if(test == rand[i]){
output_high(LED2);
}else{
output_low(LED2);
}
i=i+1;
}
}
}
}
I do not understand why I have that difference, can anybody help me please?

Thanks
dyeatman



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

View user's profile Send private message

PostPosted: Wed Jun 11, 2014 7:18 am     Reply with quote

The datasheet I am reading says the Read AND Write cycle times
are either 55 or 70ns MINIMUM depending on the two digits at the end
of the part number so 50ns is too fast.

Without using FAST_IO the Set Port function is useless.
_________________
Google and Forum Search are some of your best tools!!!!
bourne



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 2:11 am     Reply with quote

Hello,

I write those #use FAST IO:
#use FAST_IO(D)
#use FAST_IO(G)
#use FAST_IO(H)
#use FAST_IO(J)

I did not know if it was necessary for the address ports so I tried with and without, I have no changed, the LED is blinking even if it should not...

My functions write and read are they correct? I wonder if there isn't an error, but I cannot find where...

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 2:30 am     Reply with quote

It's not 'necessary to address ports'. It makes it your job to set TRIS correctly. Without these, the compiler takes over controlling the TRIS, and will do it automatically based upon the operations you perform on the port. Makes touching TRIS yourself pointless and unnecessary. For 99% of users, unless they want the ultimate speed or are doing something like outputting a few bits at once on a port they want to otherwise remain as input, it is safer, and simpler to just ignore TRIS completely, and let the compiler handle it.
The point is that without the fast_io lines, these lines:

set_tris_a(0xBC); //CLKI in input et CLKO in output
set_tris_h(0x00); //port h, g et j in output
set_tris_g(0b00000);
set_tris_j(0x00);
set_tris_c(0x80); //port C in input pour RX,

Basically won't work, since the compiler _will_ override them itself.
bourne



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 2:39 am     Reply with quote

Thank you, I took off the address port part.

the fact is that it still does not work...

Do you think my write/read functions are correct?

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 5:33 am     Reply with quote

some things....
what voltage is the PIC powered by ?

though NOT an error,rather a programming style, you should rename your functions to write_cypress(), read_cypress(). Just 'read' and 'write' will be confusing later, especially if you add other devices.

play 'computer' and put a scope, DVM or LEDs on the I/O pins(remove the Cypress part) and see what is happening.'single step' through a write and a read 'cycle' and confirm the correct pins are being used.

hth
jay
bourne



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 5:48 am     Reply with quote

thank you for your response Jay

I put 5V on the card, and then a regulator is powering the PIC, on that part everything is ok.

There is a big problem, when I write in the memory and then I try to read I do not have the same.
The problem is the following, I write a data to an adress, then I do the same to another adress.
When I try to read at the adress of the first data, I take back the last data written.
Here is the code:
Code:

   output_h(0x01);
   output_j(0x01);   
   output_g(0b00000);      
   delay_us(1);
   write('r');   

    output_h(0x02);   
   output_j(0x02);   
   output_g(0b00000);
   delay_us(1);
   write('5');   
   
   output_h(0x01);   
   output_j(0x01);   
   output_g(0b00000);   
   delay_us(1);
   test=read();

test was '5' and not 'r'
I do not understand why I do not take the data at the adress that I wrote.

Does anybody have an idea?

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 12, 2014 7:00 am     Reply with quote

you need to show us your complete program not just 'bits' of it..

Also it would really help to define 'actions'. IE instead of 'output_h(0x01); something like cypress_high_address( 0x01); gives you and us a better idea what you're doing. Actually a small macro or function to create the address as it spans two ports is much better.

something like

write_cypress( address,data);
read_cypress(address,data);
where address is a 20bit number(int32) and data is an 8bit number(int8).

Also there are a LOT of 'chip enables' to this device.You should have them 'defined' and create a function that properly sets/resets them based on required action.

I don't have that device and cannot create the 'driver ' for you as I can't test it, that's why you need to show us your program.

Also ,most PICs will default peripherals like ADC to I/O pins. You need to disable them early in your code.

What is the real PIC and Cypress Vdd ?

hth
jay
bourne



Joined: 07 May 2014
Posts: 10

View user's profile Send private message

PostPosted: Fri Jun 13, 2014 5:40 am     Reply with quote

problem solved, the memory had a problem

thanks to all of you for your help
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