Beispiel #1
0
void process_flash_read(void){
	__xdata char msg[] = "?? ?? ?? ?? ?? ?? ?? ?? ";
	BYTE i,d;
	
	busy_polling();
    FLASH_ENABLE;				// assert chip select
    putcSPI(SPI_READ);			// send read command
    putcSPI(flash_addr_h);		// send high byte of address
    putcSPI(flash_addr_m);		// send high byte of address
    putcSPI(flash_addr_l);		// send low byte of address
	for(i = 0; i < 8; i++){
		d = getcSPI();
		msg[i*3] = hex_char_h(d);
		msg[i*3+1] = hex_char_l(d);
		msg[i*3+2] = ' ';
	}
	FLASH_DISABLE;				// negate chip select
	if(flash_addr_l == (256 - 8)){
		flash_addr_l = 0x00;
		if(flash_addr_m == 0xFF)
			flash_addr_h++;
		flash_addr_m++;
	}
	else
		flash_addr_l += 8;
	print_ep6_string(msg);
}
Beispiel #2
0
void process_flash_unlock(void){
	busy_polling();
    FLASH_ENABLE;		// assert chip select
    putcSPI(SPI_WREN);  // write status command
    FLASH_DISABLE;		// negate chip select
    FLASH_ENABLE;		// assert chip select
    putcSPI(SPI_WRSR);  // Write SR
    putcSPI(0x00);  	// Clear all bits
    FLASH_DISABLE;      // negate chip select
	print_ep6_string("Done");
}
Beispiel #3
0
unsigned char WriteSPIM( unsigned char data_out )
{
#ifdef __PIC32MX__
    BYTE   clear;
    putcSPI((BYTE)data_out);
    clear = getcSPI();
    return ( 0 );                // return non-negative#
#elif defined __18CXX
    BYTE clear;
    clear = SPIBUF;
    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = data_out;
    if (SPICON1 & 0x80)
        return -1;
    else
        while (!SPI_INTERRUPT_FLAG);
    return 0;
#else
    BYTE   clear;
    SPIBUF = data_out;          // write byte to SSP1BUF register
    while( !SPISTAT_RBF ); // wait until bus cycle complete
    clear = SPIBUF;
    return ( 0 );                // return non-negative#
#endif
}
Beispiel #4
0
// *------------------------------------------------------*
inline void __attribute__((always_inline)) vSPIPut(UINT8 data){
    UINT8 clear;
    
    putcSPI((UINT8)data);
    clear = getcSPI();
    return; 
}
Beispiel #5
0
void process_flash_erase(void){
	BYTE status_reg = 1;
	busy_polling();
    FLASH_ENABLE;		// assert chip select
    putcSPI(SPI_WREN);  // write status command
    FLASH_DISABLE;		// negate chip select
    FLASH_ENABLE;		// assert chip select
    putcSPI(SPI_BE);  	// Bulk Erase command
    FLASH_DISABLE;      // negate chip select
	while((status_reg & 0x01) != 0){// Pulling Flash Busy
        FLASH_ENABLE;			//assert chip select
        putcSPI(SPI_RDSR1);		//send read status command
        status_reg = getcSPI();	//read data byte
        FLASH_DISABLE;			//negate chip select
	}
	print_ep6_string("Done");
}
Beispiel #6
0
void process_flash_status(void){
	BYTE sr1, sr2;
	char msg[] = "SR1 ?? SR2 ??";
	
	FLASH_ENABLE;			// assert chip select
    putcSPI(SPI_RDSR1);		// Read Status Register 1
	sr1 = getcSPI();
   	FLASH_DISABLE;			// negate chip select
	FLASH_ENABLE;			// assert chip select
    putcSPI(SPI_RDSR2);		// Read Status Register 1
	sr2 = getcSPI();
   	FLASH_DISABLE;			// negate chip select
	msg[4] = hex_char_h(sr1);
	msg[5] = hex_char_l(sr1);
	msg[11] = hex_char_h(sr2);
	msg[12] = hex_char_l(sr2);
	print_ep6_string(msg);
}
Beispiel #7
0
unsigned int spi_transfer(unsigned int nr, unsigned short data){

	unsigned char 	a = (0xFF00 & data)>>8;
	unsigned char b = (0xFF&data);
	unsigned short a1,b1;	

	CS_3 = 1;
	CS_4 = 1;
	CS_9 = 1;
	CS_6 = 1;

	if(nr==0) CS_3 = 0; 
	if(nr==1) CS_4 = 0; 
	if(nr==2) CS_9 = 0; 
	if(nr==3) CS_6 = 0; 


	putcSPI(a);
	while(!DataRdySPI()){
	}
	a1 = SSP1BUF;	

	putcSPI(b);
	while(!DataRdySPI()){
	}
	b1 = SSP1BUF;	

	CS_3 = 1;
	CS_4 = 1;
	CS_9 = 1;
	CS_6 = 1;

	data = ((a1<<8)&0xFF00) | b1;

	return data;
}
Beispiel #8
0
void process_flash_id(void){
	BYTE mid, did, uid;
	char msg[] = "IDCODE ??????";
	
	busy_polling();
	FLASH_ENABLE;        	// assert chip select
    putcSPI(SPI_RDID);  	// get ID command
	mid = getcSPI();
	did = getcSPI();
	uid = getcSPI();
 	FLASH_DISABLE;       	// negate chip select
	msg[7] = hex_char_h(mid);
	msg[8] = hex_char_l(mid);
	msg[9] = hex_char_h(did);
	msg[10] = hex_char_l(did);
	msg[11] = hex_char_h(uid);
	msg[12] = hex_char_l(uid);
	print_ep6_string(msg);
	//if((mid == 0xEF) && (did == 0x40) && (uid == 0x17))
	//	print_ep6_string("W25Q64FV");
	//if((mid == 0x20) && (did == 0x20) && (uid == 0x16))
	//	print_ep6_string("M25P32");
}
Beispiel #9
0
/*****************************************************************************
  Function:
    BYTE MDD_SDSPI_ReadMedia (void)
  Summary:
    Reads a byte of data from the SD card.
  Conditions:
    None.
  Input:
    None.
  Return:
    The byte read.
  Side Effects:
    None.
  Description:
    The MDD_SDSPI_ReadMedia function will read one byte from the SPI port.
  Remarks:
    This function replaces ReadSPI, since some implementations of that function
    will initialize SSPBUF/SPIBUF to 0x00 when reading.  The card expects 0xFF.
  ***************************************************************************************/
BYTE MDD_SDSPI_ReadMedia(void)
{

#ifdef __C32__

    putcSPI((BYTE)0xFF);
    return (BYTE)getcSPI();

#elif defined __18CXX

    BYTE clear;
    clear = SPIBUF;
    SPI_INTERRUPT_FLAG = 0;
    SPIBUF = 0xFF;
    while (!SPI_INTERRUPT_FLAG);
    return SPIBUF;

#else
    SPIBUF = 0xFF;                              //Data Out - Logic ones
    while(!SPISTAT_RBF);                     //Wait until cycle complete
    return(SPIBUF);                             //Return with byte read
#endif
}
Beispiel #10
0
// *------------------------------------------------------*
inline UINT8 __attribute__((always_inline)) uiSPIGet(void){
	
	putcSPI((UINT8)0xFF);
    return((UINT8)getcSPI());
}