#include "RF430.h" #include //Header einbinden #include #include "init_device.h" unsigned char NDEF_Application_Data[] = RF430_DEFAULT_DATA; int var, rdata; short temp; unsigned char var_l; unsigned char var_h; //writes the register at reg_addr and incrementing addresses with the data at "write_data" of length data_length void Write_Continuous(unsigned int reg_addr, unsigned char* write_data, unsigned int data_length) { unsigned int i; unsigned char TxAddr[2] = {0,0}; TxAddr[0] = reg_addr >> 8; //MSB of address TxAddr[1] = reg_addr & 0xFF; //LSB of address PORTBbits.RB5 = 0; //CS=0 SPI2BUF = 0x02; while(!SPI2STATbits.SPIRBF); //wait SPI2STATbits.SPIEN = 0; SPI2CON1bits.MODE16 = 1; //SPI = 16bit SPI2STATbits.SPIEN = 1; //write address SPI2BUF = reg_addr; while(!SPI2STATbits.SPIRBF); //wait SPI2STATbits.SPIEN = 0; SPI2CON1bits.MODE16 = 0; //SPI = 8bit SPI2STATbits.SPIEN = 1; //write the data for(i = 0; i < data_length; i++) { SPI2BUF = write_data[i]; while(!SPI2STATbits.SPIRBF); //wait } //PORTBbits.RB14 = 1; //SS2=1 PORTBbits.RB5 = 1; //CS=1 } //writes the register at addr with value void Write_Register(unsigned int reg_addr, unsigned char value) { PORTBbits.RB5 = 0; //CS=0 SPI2BUF = 0x02; while(!SPI2STATbits.SPIRBF); //wait SPI2STATbits.SPIEN = 0; SPI2CON1bits.MODE16 = 1; //SPI = 16bit SPI2STATbits.SPIEN = 1; //write address SPI2BUF = reg_addr; while(!SPI2STATbits.SPIRBF); //wait SPI2STATbits.SPIEN = 0; SPI2CON1bits.MODE16 = 0; //SPI = 8bit SPI2STATbits.SPIEN = 1; SPI2BUF = value; while(!SPI2STATbits.SPIRBF); //wait //PORTBbits.RB14 = 1; //SS2=1 PORTBbits.RB5 = 1; //CS=1 } int main (void) { RCONbits.SWDTEN = 0; //Watchdog init_oscillator(); init_ports(); initIO(); //SPI konfigurieren SPI2STATbits.SPIEN = 0; //SPI disable SPI2CON1bits.DISSCK = 0; //Clock intern SPI2CON1bits.DISSDO = 0; //SDO enable SPI2CON1bits.MODE16 = 0; //8bit SPI2CON1bits.CKE = 1; //Clock edge select SPI2CON1bits.SSEN = 0; //kein Slave SPI2CON1bits.CKP = 0; //Clock polarity select SPI2CON1bits.MSTEN = 1; //Master mode SPI2CON1bits.SMP = 1; //Input data sampled at end of data output time SPI2CON1bits.SPRE = 0b110; //Secondary Prescale SPI2CON1bits.PPRE = 0b10; //Primary prescale, CLK 2,5 MHz SPI2CON2bits.FRMEN = 0; //Framed SPI support aus SPI2CON2bits.SPIFSD = 0; RPOR4bits.RP9R = 0b01011; //RP9 ist SCK RPOR1bits.RP2R = 0b01010; //RP2 ist SDO RPINR22bits.SDI2R = 0b00110; //RP6 ist SDI IEC0bits.SPI1IE = 0; SPI2STAT = 0x8000; //SPI enable __delay32(10000); //leave time for the RF430CL33H to get itself initialized /****************************************************************************/ /* Configure RF430CL330H for Typical Usage Scenario */ /****************************************************************************/ //write NDEF memory with Capability Container + NDEF message Write_Continuous(0, NDEF_Application_Data, 48); //Enable interrupts for End of Read and End of Write Write_Register(INT_ENABLE_REG, 0x03); //Configure INTO pin for active low and enable RF Write_Register(CONTROL_REG, 0x02); __delay32(1000); while(1){ Write_Register(CONTROL_REG, 0x43); __delay32(2000); } }