Re: MPC555 QSPI init problems

"blogsyndrome" <[email protected]> Fri, 15 Jun 2007 01:47:10 -0000
Newsgroups gmane.comp.hardware.motorola.microcontrollers
Message-ID <[email protected]>
Have you found anything else new?  any update on your progress?
I have an eeprom chip i need to interact with.  Not sure if its
hardware hookup or my software initialization.

How are you debugging?

Also what happens with 16 bit QSMCM.TRANRAM[?].B  when your initialize
the spi as 8 bit transfers?  does it just send the 8 right
justified bits and move on to the next QSMCM.TRANRAM[?+1].B?


below are my attempts:

void setup_qsmcm() 
{
	QSMCM.QSMCR.B.STOP = 0;
	QSMCM.QSMCR.B.FRZ1 = 0;
	QSMCM.QSMCR.B.SUPV = 0;

		
	QSMCM.SPCR1.B.SPE = 0;		//disable qspi


	// PORTQS Pin Assignment Register (Basically prepare to be setup as a
QSPI)
	QSMCM.PQSPAR.B.QPAPCS3 = 1; 				// 1 = Pin is assigned PCS3 function
else GPIO pin
	QSMCM.PQSPAR.B.QPAPCS2 = 1;					// 1 = Pin is assigned PCS2 function
else GPIO pin
	QSMCM.PQSPAR.B.QPAPCS1 = 1; 				// 1 = Pin is assigned PCS1 function
else GPIO pin
	QSMCM.PQSPAR.B.QPAPCS0 = 1; 				// 1 = Pin is assigned PCS[0]
function else GPIO pin
	QSMCM.PQSPAR.B.QPAMOSI = 1; 				// 1 = Pin is assigned MOSI function
	QSMCM.PQSPAR.B.QPAMISO = 1; 				// 1 = Pin is assigned MISO function


	//PORTQS Data Direction Register (DDRQS)
	QSMCM.DDRQS.B.QDDPCS3 = 1;
	QSMCM.DDRQS.B.QDDPCS2 = 1;
	QSMCM.DDRQS.B.QDDPCS1 = 1;
	QSMCM.DDRQS.B.QDDPCS0 = 1;
		// pins serve as chip selecter; therefore enable all PCS pins as
outputs.
		// currently only using QDDPCS0

	QSMCM.DDRQS.B.QDDSCK  = 1; 					// 1 = Pin direction is output
	QSMCM.DDRQS.B.QDDMOSI = 1; 					// 1 = Pin direction is output;
master output slave input
	QSMCM.DDRQS.B.QDDMISO = 0; 					// 0 = Pin direction is input; master
input slave ouput

	
	QSMCM.SPCR0.B.MSTR = 1;						// 1 = QSPI is the system master and can
initiate transmission to external SPI devices.
	QSMCM.SPCR0.B.WOMQ = 0;						// 0 = Pins designated for output by
DDRQS operate in normal mode.
	QSMCM.SPCR0.B.BITS = 0b1000;				// 8 bits per transfer
	QSMCM.SPCR0.B.CPOL = 0;						// Clock polarity.
	QSMCM.SPCR0.B.CPHA = 1;						// Clock phase. 
	QSMCM.SPCR0.B.SPBR = 0x03;					// 6.66mhz value between 2-255 
fsys/(2*0x03) = 6.66E6
	
	
	QSMCM.SPCR1.B.DSCKL = 0x2;					// 50 nano second delay (PCS to SCK
Delay) 1 to 127
	QSMCM.SPCR1.B.DTL = 0xFF;					// Length of delay after transfer. 1 to 255
	
	
	QSMCM.SPCR2.B.WREN = 0;						// disable wrap around mode
	QSMCM.SPCR2.B.WRTO = 0;						// Wrap to pointer address 0x0
												// these settings disable spi after completion

	QSMCM.SPCR2.B.ENDQP	= 0x0;					// Ending queue pointer. [application
should only move endqp]
	QSMCM.SPCR2.B.NEWQP	= 0x0;					// New queue pointer value.


	QSMCM.SPCR3.B.LOOPQ = 0;
	QSMCM.SPCR3.B.HALT = 0;


	// interrupt pins
	QSMCM.SPCR2.B.SPIFIE = 0; // SPI finished interrupt enable.
	QSMCM.SPCR3.B.HMIE = 0;

}








void eeprom_read(unsigned char address, unsigned char *data, unsigned
char length)
{
	int i = 0;
	
  	QSMCM.SPCR2.B.ENDQP	= 0x1;

   	for(i=0; i<=3; i++)
   	{
		QSMCM.COMDRAM[i].B.CONT  = 0;
		QSMCM.COMDRAM[i].B.BITSE = 1;
		QSMCM.COMDRAM[i].B.DT    = 1;
		QSMCM.COMDRAM[i].B.DSCK  = 1;
		QSMCM.COMDRAM[i].B.PCS3  = 0;
		QSMCM.COMDRAM[i].B.PCS2  = 0;
		QSMCM.COMDRAM[i].B.PCS1  = 0;
		QSMCM.COMDRAM[i].B.PCS0  = 1;
   	}
	
	QSMCM.TRANRAM[0].B = 0x03;		// Send Read OpCode 
	QSMCM.TRANRAM[1].B = 0x00;		// high address
	QSMCM.TRANRAM[2].B = 0x10;		// low address	
	QSMCM.TRANRAM[3].B = 0x0;		// dummy data	
	
	
	QSMCM.SPCR1.B.SPE = 1;

	while(QSMCM.SPSR.B.SPIF != 1);


	*data = (unsigned char)QSMCM.RECRAM[3].B;
}


void eeprom_writechar(unsigned int address, char data )
{
	int i = 0;
	
   	QSMCM.SPCR2.B.ENDQP	= 0x3;		// Ending queue pointer; 0x0 - 0x1F =
0-31;
   									// Execution of 0 and 1 commands
	for(i=0; i<=4; i++)
	{
		QSMCM.COMDRAM[i].B.CONT  = 0; 	// 0 = Control of chip selects
returned to PORTQS after transfer is complete.
		QSMCM.COMDRAM[i].B.BITSE = 1; 	// 1 = Number of bits set in BITS
field of SPCR0.
		QSMCM.COMDRAM[i].B.DT    = 1; 	// 1 = SPCR1 DTL[7:0] specifies delay
after transfer PCS valid to SCK.
		QSMCM.COMDRAM[i].B.DSCK  = 1; 	// 1 = SPCR1 DSCKL[6:0] specifies
delay from PCS valid to SCK.
		QSMCM.COMDRAM[i].B.PCS3  = 0;
		QSMCM.COMDRAM[i].B.PCS2  = 0;
		QSMCM.COMDRAM[i].B.PCS1  = 0;
		QSMCM.COMDRAM[i].B.PCS0  = 1;	// select this spi device for serial
receive & transfer
			// up to 32 commands;
	}

	
	QSMCM.TRANRAM[0].B = 0x06;				// Write Enable prior to Write	
	QSMCM.TRANRAM[1].B = 0x02;				// Send Write OpCode
	QSMCM.TRANRAM[2].B = 0x00;				// high address
	QSMCM.TRANRAM[3].B = 0x11;				// low address	
	QSMCM.TRANRAM[4].B = data;
		// 16 bits; 32 transmit data blocks
		

	QSMCM.SPCR1.B.SPE = 1;						// 1 = QSPI is enabled. Pins allocated by
PQSPAR are controlled by the QSPI.
												// since wrap around is disabled... qspi is disabled after
execution of commands

	while(QSMCM.SPSR.B.SPIF != 1);
		// all commands in spi have been completed.
}
















--- In [email protected], "csjessid" <csjessid@...> wrote:
>
> Hi,
> I´m trying to setup a QSPI communication with the MPC555 (master) and 
> a Fujitsu microcontroller (slave), but I can´t configure the MPC 
> correctly. I programm it with Matlab/Simulink based on Target 
> Language Compiler files and this is the external c-code:
> 
> -------------------------------------------------------------------
> UINT8 InitQSPI (void)
> 
> {
> 
> unsigned int ret = 0;
> 
> if (!qspi_config) {
> 
> QSMCM.PQSPAR.R = 3; // MOSI/MISO
> 
> QSMCM.DDRQS.R = 0x06; // MOSI, SCK Out, MISO In
> 
> QSMCM.SPCR0.R = 0x8308; // Master, 16-bit, SPBR 
> 
> QSMCM.SPCR2.R = 0x0200; // queue size of 3 words */
> 
> QSMCM.SPCR3.R = 0x0000; // normal operation */
> 
> QSMCM.COMDRAM[0].R = 0x00; /* force 8-bit */
> 
> QSMCM.COMDRAM[1].R = 0x00; /* 16-bit */
> 
> QSMCM.COMDRAM[2].R = 0x00; /* 16-bit */
> 
> QSMCM.TRANRAM[0].R = 0x00; /* 1st data word */
> 
> QSMCM.TRANRAM[1].R = 0x0000; /* 2nd data word */
> 
> QSMCM.TRANRAM[2].R = 0x0000; /* 3rd data word */
> 
> QSMCM.RECRAM[0].R = 0x0; /* clear rx data word */
> 
> QSMCM.RECRAM[1].R = 0x0; /* clear rx data word */
> 
> QSMCM.RECRAM[2].R = 0x0; /* clear rx data word */
> 
> QSMCM.SPCR1.R = 0x0101; /* SPI disabled */
> 
> qspi_config = 1;
> 
> ret = 1;
> 
> 
> } return ret;
> 
> 
> } /* end of InitSPI */
> 
> 
> /* ------------ send tx ------------------ */
> 
> UINT8 SPI_tx (UINT32 data)
> 
> {
> 
> UINT16 highbyte, lowbyte;
> 
> unsigned int ret = 0;
> 
> highbyte = data >> 16; 
> 
> lowbyte = data; 
> 
> if (!transmitted) {
> 
> QSMCM.TRANRAM[0].R = data >> 16; 
> 
> QSMCM.TRANRAM[1].R = highbyte; 
> 
> QSMCM.TRANRAM[2].R = lowbyte; 
> 
> QSMCM.SPSR.B.SPIF = 0; 
> 
> QSMCM.SPCR1.B.SPE = 1;
> 
> transmitted = 1;
> 
> ret = 1;
> 
> while (QSMCM.SPSR.B.SPIF == 0); 
> 
> }
> 
> return ret;
> 
> } 
> -------------------------------------------------------------------
> 
> in my simulink model, I read the return-values of the functions and 
> send them via CAN to check if the routine was called successfully... 
> But if I write SPCR2, SPCR3 or COMDRAM, I don´t receive anything from 
> the CAN interface. As if the communication breaks down. What could be 
> the problem? is the c-code correct? If yes, it has to be a problem 
> with my model/sfunction/tlc in simulink.
> 
> greetings
> 
> Christian
>