/** * @mainpage PIC32 test project * * @section Introduction * * @details This projects only purpose is to test pic32 functions and hold it so * it is easy to find and reuse the written code. * * @tableofcontents * */ #include "xc.h" #include "i2c_drv.h" // DEVCFG3 #pragma config USERID = 0xFFFF // Enter Hexadecimal value (Enter Hexadecimal value) #pragma config FMIIEN = OFF // Ethernet RMII/MII Enable (RMII Enabled) #pragma config FETHIO = OFF // Ethernet I/O Pin Select (Alternate Ethernet I/O) #pragma config PGL1WAY = OFF // Permission Group Lock One Way Configuration (Allow multiple reconfigurations) #pragma config PMDL1WAY = OFF // Peripheral Module Disable Configuration (Allow multiple reconfigurations) #pragma config IOL1WAY = OFF // Peripheral Pin Select Configuration (Allow multiple reconfigurations) #pragma config FUSBIDIO = OFF // USB USBID Selection (Controlled by Port Function) // DEVCFG2 #pragma config FPLLIDIV = DIV_1 // System PLL Input Divider (1x Divider) #pragma config FPLLRNG = RANGE_5_10_MHZ // System PLL Input Range (5-10 MHz Input) #pragma config FPLLICLK = PLL_FRC // System PLL Input Clock Selection (FRC is input to the System PLL) #pragma config FPLLMULT = MUL_50 // System PLL Multiplier (PLL Multiply by 50) #pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (2x Divider) #pragma config UPLLFSEL = FREQ_24MHZ // USB PLL Input Frequency Selection (USB PLL input is 24 MHz) // DEVCFG1 #pragma config FNOSC = SPLL // Oscillator Selection Bits (System PLL) #pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value) #pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disable SOSC) #pragma config IESO = OFF // Internal/External Switch Over (Disabled) #pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled) #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled) #pragma config FCKSM = CSECME // Clock Switching and Monitor Selection (Clock Switch Enabled, FSCM Enabled) #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576) #pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming) #pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode) #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled) #pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%) #pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648)) #pragma config FDMTEN = OFF // Deadman Timer Enable (Deadman Timer is disabled) // DEVCFG0 #pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled) #pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled) #pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (Communicate on PGEC1/PGED1) #pragma config TRCEN = OFF // Trace Enable (Trace features in the CPU are disabled) #pragma config BOOTISA = MIPS32 // Boot ISA Selection (Boot code and Exception code is MIPS32) #pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable)) #pragma config FSLEEP = OFF // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode) #pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission (Allow CPU access to all permission regions) #pragma config SMCLR = MCLR_NORM // Soft Master Clear Enable bit (MCLR pin generates a normal system Reset) #pragma config SOSCGAIN = GAIN_1X // Secondary Oscillator Gain Control bits (1x gain setting) #pragma config SOSCBOOST = OFF // Secondary Oscillator Boost Kick Start Enable bit (Normal start of the oscillator) #pragma config POSCGAIN = GAIN_1X // Primary Oscillator Gain Control bits (1x gain setting) #pragma config POSCBOOST = OFF // Primary Oscillator Boost Kick Start Enable bit (Normal start of the oscillator) #pragma config EJTAGBEN = NORMAL // EJTAG Boot (Normal EJTAG functionality) // DEVCP0 #pragma config CP = OFF // Code Protect (Protection Disabled) // SEQ3 #pragma config TSEQ = 0x0 // Boot Flash True Sequence Number (Enter Hexadecimal value) #pragma config CSEQ = 0xFFFF // Boot Flash Complement Sequence Number (Enter Hexadecimal value) int main(void) { uart_drv_init(); //enable selfhold pin TRISDbits.TRISD1 = OUTPUT; LATDbits.LATD1 = HIGH; //initializations i2c_drv_init(); i2c_hal_type test_i2c_hal; uint8_t cmd_buffer[100 * sizeof (int)]; uint8_t write_buffer[500]; uint8_t read_buffer[500]; i2c_hal_init(&test_i2c_hal, cmd_buffer, sizeof (cmd_buffer), write_buffer, sizeof (write_buffer), read_buffer, sizeof (read_buffer)); i2c_hal_cb_start_set(&test_i2c_hal, i2c_drv_tx_start, i2c_drv_tx_start_handler, NULL, NULL); i2c_hal_cb_restart_set(&test_i2c_hal, i2c_drv_tx_restart, i2c_drv_tx_restart_handler, NULL, NULL); i2c_hal_cb_stop_set(&test_i2c_hal, i2c_drv_tx_stop, i2c_drv_tx_stop_handler, NULL, NULL); i2c_hal_cb_ack_set(&test_i2c_hal, i2c_drv_tx_ack, i2c_drv_tx_ack_handler, i2c_drv_rx_ack, i2c_drv_rx_ack_handler); i2c_hal_cb_nack_set(&test_i2c_hal, i2c_drv_tx_nack, i2c_drv_tx_nack_handler, i2c_drv_rx_nack, i2c_drv_rx_nack_handler); i2c_hal_cb_data_set(&test_i2c_hal, i2c_drv_tx_data, i2c_drv_tx_data_handler, i2c_drv_rx_data, i2c_drv_rx_data_handler); i2c_hal_collision_check_cb_set(&test_i2c_hal, i2c_drv_error_check); i2c_hal_busy_check_cb_set(&test_i2c_hal, i2c_drv_busy_check); // eeprom_drv_init(); //ringbuffer test while (1) { //start while (i2c_drv_tx_start() == EXIT_FAILURE)continue; while (i2c_drv_tx_start_handler() == EXIT_FAILURE)continue; //adresse while (i2c_drv_tx_data(0b10101000) == EXIT_FAILURE)continue; while (i2c_drv_tx_data_handler() == EXIT_FAILURE)continue; //ack while (i2c_drv_rx_ack_handler() == EXIT_FAILURE)continue; while (i2c_drv_rx_ack() == EXIT_FAILURE)continue; uint8_t data; //read byte 1 while (i2c_drv_rx_data_handler() == EXIT_FAILURE)continue; while (i2c_drv_rx_data(&data) == EXIT_FAILURE)continue; while (i2c_drv_tx_ack() == EXIT_FAILURE)continue; while (i2c_drv_tx_ack_handler() == EXIT_FAILURE)continue; i2c_drv_tx_ack(); while (i2c_drv_tx_ack_handler() == EXIT_FAILURE)continue; //stop i2c_drv_tx_stop(); //delay int i = 0; for (i = 0; i < 0xffff; i++)continue; for (i = 0; i < 0xffff; i++)continue; for (i = 0; i < 0xffff; i++)continue; for (i = 0; i < 0xffff; i++)continue; } return 1; }