/*Beginn der SPI.c-Datei*/ typedef enum { write = 0, read = 1 } SPI_TRANSFER_MODE_TYPE; SPI_TRANSFER_MODE_TYPE transferMode; unsigned char txCnt; //Hilfsvariable zum merken der Sendezyklen unsigned char rxCnt; //Hilfsvariable zum merken der Lesezyklen unsigned char transferCnt; //Hilfsvariable zum Vergleichen der maximal zu sendenden Bytes unsigned char txBuf[3]; //Beinhaltet das Instruktion-Byte und die 2-Byte-Adresse unsigned char *pUserData; //Hilfspointer zur Übergabe/Speicherung der tx -bzw. rx-Buffer // des SPI-Interfaces vom TriCore //------------------------------------------------------------------------ // hiermit wird das Konfigurrationsregister der SSC0-Schnitstelle des TCs beschrieben SSC0_CON.U = SSC_CON_WORD_LENGTH_8 | SSC_CON_MSB_FIRST | SSC_CON_LATCH_LEADING_SHIFT_TRAILING | SSC_CON_CLK_IDLE_POL_ZERO | SSC_CON_LOOP_BACK_DISABLED | SSC_CON_MASTER_MODE | SSC_CON_ENABLED; //------------------------------------------------------------------------- void SPI_25128_WRITE(unsigned int addr, unsigned char *data, unsigned char num) { /* must remove the protection before every write to the EEPROM */ SPI_25128_WREN(); // To enable the Write-Protection of the EEPROM /* wait for SSC0 to finish if busy */ while ((SSC0_STAT.U & SSC_STAT_BUSY_FLAG) == SSC_STAT_BUSY_FLAG) { ; } /* set control/buffer to the correct mode and address */ transferMode = write; txBuf[0] = WRITE; // Beinhaltet die Instruktorkodierung txBuf[1] = (unsigned char) (addr >> 8); // Die Adresse wird MSB-First versendet D[15:0] txBuf[2] = (unsigned char) (addr); txCnt = 1; /* mark that we already sent one byte out */ transferCnt = num + 3; /* indicated the total number of transfers */ pUserData = &data[0]; /* hold user pointer information for IRQs */ /* clear and enable transmit interrupt */ SSC0_TSRC.U = 0x00001003; /* disable receive interrupt */ SSC0_RSRC.U = 0x00001000; // Zuvor Interrupt Level 4; 0x00001004 /* write first byte (command) to serial EEPROM start transfer */ SSC0_TB.U = txBuf[0]; // Hier wird dem transceive-Buffers des TriCores der Instruktor übergeben IO_vResetPin(IO_P7_0); }//End of SPI_25128_WRITE //------------------------------------------------------------------------ void SPI_ServiceTxIrq(void) // Diese Fkt wird durch den Transciever-Interrupt ausgelöst { /* are we finished sending the command and address? */ if (txCnt < 3) { /* no still sending the address bytes */ SSC0_TB.U = txBuf[txCnt]; } else { /* has the complete user data be written to the EEPROM? */ if (txCnt < transferCnt) { /* check the transfer mode, are we writing or reading EEPROM data? */ if (transferMode == write) { /* write user data to the serial EEPROM */ SSC0_TB.U = *pUserData++; } else { /* just sending dummy data to clock the EEPROM for read data */ SSC0_TB.U = 0; } } } txCnt++; }// End of SPI_ServiceTxIrq //------------------------------------------------------------------------- . . . /*Ende der SPI.c-Datei*/ /*Beginn der MAIN.c-Datei*/ unsigned char myOutString[] = {0x15}; //String mit dem Inhalt welcher versendet werden soll unsigned char myOutStringCnt = sizeof(myOutString); // Zur Bestimmung der Stringgröße für die Funktion unsigned char myInString[64]; // String, welcher den Inhalt auf der MISO-Line . // durch den receive-Buffer erhält . . void main(void) { SPI_25128_WRITE(0x0030,&myOutString[0],myOutStringCnt); return 0; }