読者です 読者をやめる 読者になる 読者になる

Lynx-EyEDの電音鍵盤 新館

広帯域制御屋の駄文とか

ソースコード再来

えー、日が改まってしまいましたがCMD18のリード命令も付加したコード全文をUPします。
ちゃんと正しい内容が書き込まれて、リードされてるかをチェックしています。コードでは0xABを書き込み0xABが読み込めたらp1_5端子をLowにしています。
p1_5端子に他端を+5Vに抵抗でプルアップしたLEDをつなぐと、正しい値が読み込めたときにLEDがONします。

/***********************************************************************/
/*                                                                     */
/*  FILE        :R8_MMC_01.c                                           */
/*  DATE        :Fri, Mar 17, 2006                                     */
/*  DESCRIPTION :Main Program                                          */
/*  CPU TYPE    :Other                                                 */
/*                                                                     */
/*  This file is generated by Renesas Project Generator (Ver.4.0).     */
/*                                                                     */
/***********************************************************************/

#include 
void set_CLK20(void);




////////////////////////////////////////////////
void set_CLK20(void){
prc0=1;
cm1=0x08;
cm0=0x08;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
ocd2=0;
prc0=0;
}


////////////////////////////////////////////////
//	MMC read & write
////////////////////////////////////////////////
#define MMC_SCS p3_4


void main(void){

char c,dummy;
int w;

set_CLK20();
//////////////// init port /////////////////////

p3=0b10010000;
pd3=0b10010000;
//p1_6 = 1;
//pd1_6 = 0;//input
pd1_5 = 1;
p1_5=1;
sser=0;
ssmr2= 0x41;
sscrh=0x60;		//master f1/256
ssmr=0x08;
sssr=0;

/////////////////////////////////////////////////
// 		MMC initialize
//	sser = 0x10 means te=1 re=0
//	sser = 0x08 means te=0 re=1
/////////////////////////////////////////////////

sser = 0x10;	//te=1 re=0
for(c=10;c!=0;c++)
{
	while(!tdre_sssr);
	sstdr = 0xff;
}
while(!tend_sssr);	//wait transmit
/////////////////////////////////////////////////
//	transmit CMD0
/////////////////////////////////////////////////

MMC_SCS = 0;
sser = 0x10;		//te=1 re=0
while(!tdre_sssr);
sstdr = 0xff;		//dummy
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x40;		//CMD0=40_0000_0000_95h
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x95;		
while(!tdre_sssr);
while(!tend_sssr);	//wait trans end

//----------------------------
//	wait R1 resp
//----------------------------

sser = 0x08;		//te=0 re=1
rsstp_sscrh=1;		//receive 1 byte
dummy = ssrdr;		//dummy read
for(w=16;w!=0;w--)
	{
		while(!rdrf_sssr);	//wait resp
		dummy = ssrdr;
		if(!(dummy & 0x80))break;
		
	}//timed out



/////////////////////////////////////////////////
//	transmit CMD1
/////////////////////////////////////////////////
do{
sser = 0x10;		//te=1 re=0
orer_sssr = 0;		//clear overrun flag

while(!tdre_sssr);
sstdr = 0xff;		//dummy
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x41;		//CMD1=41_00FF_8000_99h
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0xff;		
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x80;		
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x99;		
while(!tdre_sssr);
while(!tend_sssr);	//wait trans end
//----------------------------
//	wait R1 resp
//----------------------------

sser = 0x08;		//te=0 re=1
orer_sssr=0;		//clear overrun flag

rsstp_sscrh=1;		//receive 1 byte
dummy = ssrdr;		//dummy read

for(w=16;w!=0;w--)
	{
		while(!rdrf_sssr);	//wait resp
		dummy = ssrdr;
		if(!(dummy & 0x80))break;	
	}//timed out
}while(dummy != 0x00);

for (w=100;w!=0;w--);	//wait exiting In-Idle-State
//
sser = 0;
sscrh = 0x66;		//master, f1/4

/////////////////////////////////////////////////
//	transmit CMD25(multiple write)
/////////////////////////////////////////////////
do{
sser = 0x10;		//te=1 re=0
orer_sssr = 0;		//clear overrun flag

while(!tdre_sssr);
sstdr = 0xff;		//dummy
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x59;		//CMD25=59_0000_0000_01h
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0x00;		
while(!tend_sssr);
while(!tdre_sssr);

sstdr = 0x01;
while(!tdre_sssr);		
while(!tend_sssr);	//wait trans end



//----------------------------
//	wait R1 resp
//----------------------------

sser = 0x08;		//te=0 re=1
orer_sssr = 0;		//clear overrun flag

rsstp_sscrh = 1;		//receive 1 byte
dummy = ssrdr;		//dummy read

for(w=16;w!=0;w--)
	{
		while(!rdrf_sssr);	//wait resp
		dummy = ssrdr;
		if(!(dummy & 0x80))break;
		
	}//timed out
}while(dummy != 0x00);

//----------------------------
//	start writing
//----------------------------

while(!rdrf_sssr);
sser = 0x10;		//te=1 re=0
orer_sssr = 0;		//clear overrun flag

while(!tdre_sssr);
sstdr = 0xfc;		//multiple write start token
while(!tend_sssr);
for(w=512;w!=0;w--){ 
	while(!tdre_sssr);
	sstdr = 0xAB;		// write DATA
	while(!tend_sssr);
}
while(!tdre_sssr);
sstdr = 0xff;		//CRC
while(!tend_sssr);
while(!tdre_sssr);
sstdr = 0xff;		//CRC
while(!tend_sssr);
		
//----------------------------
//	receive resp.
//----------------------------
while(!tdre_sssr);
sser = 0x08;		//te=0 re=1
orer_sssr=0;		//clear overrun flag

rsstp_sscrh=1;		//receive 1 byte
dummy = ssrdr;		//dummy read
while(1){
	while(!rdrf_sssr);
	if*1break;
		
		
	}//timed out


dummy = ssrdr;

//-----------------------------
// read start
//-----------------------------
while(1){
while(!rdrf_sssr);
	if(ssrdr==0xfe){	//get start token?
		for(w=512;w!=0;w--){ 
			while(!rdrf_sssr);
			dummy = ssrdr;			//read data
			if(dummy == 0xAB)p1_5=0;	//check 	
		}
		while(!rdrf_sssr);
		dummy = ssrdr;			//CRC
		while(!rdrf_sssr);
		dummy = ssrdr;			//CRC
	}
}







while(1);					//end






/////////////////////////////////////////////////
}

詳細は前々日のblogを参照してください。

*1:ssrdr&0x0f)==5)break; //get resp. } while(1){ while(!rdrf_sssr); if(ssrdr!=0)break; //wait busy } while(!rdrf_sssr); sser = 0x10; //te=1 re=0 orer_sssr = 0; //clear overrun flag while(!tdre_sssr); sstdr = 0xff; //dummy while(!tend_sssr); while(!tdre_sssr); sstdr = 0xfd; //stop tran token while(!tdre_sssr); while(!tend_sssr); //////////////////////////////////////////////// sser = 0x08; //te=0 re=1 orer_sssr=0; //clear overrun flag dummy = ssrdr; while(1){ while(!rdrf_sssr); if(ssrdr != 0x00)break; //wait busy } while(1){ while(!rdrf_sssr); if(ssrdr != 0x00)break; } //wait ///////////////////////////////////////////////// // transmit CMD18(multiple read) ///////////////////////////////////////////////// while(!rdrf_sssr); sser = 0x10; //te=1 re=0 orer_sssr = 0; //clear overrun flag while(!tdre_sssr); sstdr = 0xff; //dummy while(!tend_sssr); while(!tdre_sssr); sstdr = 0x52; //CMD18=52_0000_0000_01h while(!tend_sssr); while(!tdre_sssr); sstdr = 0x00; while(!tend_sssr); while(!tdre_sssr); sstdr = 0x00; while(!tend_sssr); while(!tdre_sssr); sstdr = 0x00; while(!tend_sssr); while(!tdre_sssr); sstdr = 0x00; while(!tend_sssr); while(!tdre_sssr); sstdr = 0x01; while(!tdre_sssr); while(!tend_sssr); //wait trans end //---------------------------- // wait R1 resp //---------------------------- sser = 0x08; //te=0 re=1 //orer_sssr = 0; //clear overrun flag rsstp_sscrh = 1; //receive 1 byte dummy = ssrdr; //dummy read for(w=16;w!=0;w--) { while(!rdrf_sssr); //wait resp dummy = ssrdr; if(!(dummy & 0x80