Esempio n. 1
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
}
Esempio n. 2
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);
}
Esempio n. 3
0
// *------------------------------------------------------*
inline void __attribute__((always_inline)) vSPIPut(UINT8 data){
    UINT8 clear;
    
    putcSPI((UINT8)data);
    clear = getcSPI();
    return; 
}
Esempio n. 4
0
void getsSPI( unsigned char *rdptr, unsigned char length )
{
  while ( length )                // stay in loop until length = 0
  {
    *rdptr++ = getcSPI();         // read a single byte
    length--;                     // reduce string length count by 1
  }
}
Esempio n. 5
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);
}
Esempio n. 6
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");
}
Esempio n. 7
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");
}
Esempio n. 8
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
}
Esempio n. 9
0
// *------------------------------------------------------*
inline UINT8 __attribute__((always_inline)) uiSPIGet(void){
	
	putcSPI((UINT8)0xFF);
    return((UINT8)getcSPI());
}