Discussion in "8051 Discussion Forum" started by    Help    Dec 8, 2008.
Tue Feb 24 2009, 02:56 am
Need help on this concern:::

does structures or variables defined in different manner matter?

Will they still communicate with each other?
I think this is whats wrong..

please look at this for example..
I wanna communicate MAX3421 Registers and PIC18F4550 both defined in different manner below..

For PIC18F4550
extern volatile near unsigned char       SSPBUF;
extern volatile near unsigned char       SSPCON1;
extern volatile near struct {
  unsigned SSPM0:1;
  unsigned SSPM1:1;
  unsigned SSPM2:1;
  unsigned SSPM3:1;
  unsigned CKP:1;
  unsigned SSPEN:1;
  unsigned SSPOV:1;
  unsigned WCOL:1;
} SSPCON1bits;
extern volatile near unsigned char       SSPSTAT;
extern volatile near union {
  struct {
    unsigned BF:1;
    unsigned UA:1;
    unsigned R_W:1;
    unsigned S:1;
    unsigned P:1;
    unsigned D_A:1;
    unsigned CKE:1;
    unsigned SMP:1;
  };SSPSTATbits;



For MAX3421E
#define rMODE 27<<3
// ---------bits------------
#define bmHOST          0x01
#define bmLOWSPEED      0x02
#define bmHUBPRE        0x04
#define bmSOFKAENAB     0x08
#define bmSEPIRQ        0x10
#define bmDELAYISO      0x20
#define bmDMPULLDN      0x40
#define bmDPPULLDN      0x80
#define rRCVFIFO 1<<3     
#define rSNDFIFO 2<<3 


MAX3421E registers are preshifted 3 bits left to compensate for command bits 0wa..
Will the preshift affect?
For example in the code below..


void detect_device(void)
{

      // Activate HOST mode & turn on the 15K pulldown resistors on D+ and D-
Hwreg(rMODE,(bmDPPULLDN|bmDMPULLDN|bmHOST)); 
       // Note--initially set up as a FS host (LOWSPEED=0)
Hwreg(rHIRQ,bmCONDETIRQ);  // clear the connection detect IRQ
printf("Waiting for device connect\n\n");

/*
   some other codes deleted in purpose
*/

	
}
void Hwreg(BYTE reg, BYTE val)	// write a host register
{
HSSEL_LO
SSPBUF = reg+0x02;			// command byte into the FIFO. 0x02 is the write bit
SSPBUF = val;				// data byte into the FIFO
while(BF==0&&SSPIF==0) ;	// hang until BUSY bit goes low
HSSEL_HI
}


Please Help Masters..

Tue Feb 24 2009, 03:01 pm
Hi Everyone,

I'm back again... :-)

I have facing the WriteMultipleSector() function. I alway get the R1_ILLEGAL_CMD (0x04) respond when i send the command WRITE_MULTIPLE_BLOCK (CMD25) to MMC/SD. I wonder why i alway receive the respond is 0x04?! and i also realize this CRC_ON_OFF (CMD59) command also gave the respond 0x04. Is it my card can't support this command

I have make a simple routine to test the command...

static int CMD(unsigned int addr) // WRITE_MULTIPLE_BLOCK
{
	unsigned int i, R1;
	for(i=0; i<0xFFFF; i++){
		R1 = SD_Command(CMD25, addr<<9);        
		if(R1 != 0)            
			continue;        
		return 0;    
	}    
	return R1;
}


Please someone can advice,..

Thank you,.
Tue Feb 24 2009, 10:25 pm
Tang,

I had a chance to read the Product Manual this morning, and would like to point out a couple of things:

1. Why are you sending the command over and over again?
2. I will need to see the part of SD_Command that gets the response byte.

I tested this function on my hardware, and the result R1 is returned as 0x00, which means it is now ready to receive the token byte for the start of the write.

I am using this format:
   SD_Command( CMD_WRITE_MULTIPLE_BLOCK, SDCard.database << 9 );
   Index = SD_GetR1();
   printf("\r\nResult from CMD_WRITE_MULTIPLE_BLOCK = 0x%02X", (WORD)(Index));

and you already have the source in PDF file.

This generates this output:

Result from CMD_WRITE_MULTIPLE_BLOCK = 0x00

Wed Feb 25 2009, 12:11 pm
Dear Daves,

Thank you for spending your treasure time to help me...

1. Why are you sending the command over and over again?
Actually i'm purposely to do that..hope after sending a few dummy clock to MMC/SD then will get the actual respond.

2. I will need to see the part of SD_Command that gets the response byte.
            	
SD_Command( CMD_WRITE_MULTIPLE_BLOCK, SectorNumber << 9 );
Index = SD_GetR1();
printf("\r\nResult from CMD_WRITE_MULTIPLE_BLOCK = 0x%02X", (BYTE)(Index));
printf("\r\n");

the "Index" type i decrade as BYTE because SD_GetR1() is return BYTE type variable.
On the starting i get the bellowresult..



After enter the write multiple block function and run the SD_Command() again then the result will be like..


How come the result i alway get from prinft() result is different?

Please advice,...

Thank you,..
Thu Feb 26 2009, 05:52 am
For others reading this forum...

The only types the printf() function will realize are listed in the C51 user's manual, and look like this:




Notice there are no argument types of unsigned char ???

When you want to use printf() to print an unsigned char value, you must typecast it to either an int or an unsigned int.

so, the code from Tang should have looked like this:
printf("\r\nResult from CMD_WRITE_MULTIPLE_BLOCK = 0x%02X", (WORD)(Index));


Hope this helps,

-Dave

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am