Esempio n. 1
0
int32_t main(void)
{

#ifndef PIC32_STARTER_KIT
    /*The JTAG is on by default on POR.  A PIC32 Starter Kit uses the JTAG, but
    for other debug tool use, like ICD 3 and Real ICE, the JTAG should be off
    to free up the JTAG I/O */
    DDPCONbits.JTAGEN = 0;
#endif

    /*Refer to the C32 peripheral library documentation for more
    information on the SYTEMConfig function.
    
    This function sets the PB divider, the Flash Wait States, and the DRM
    /wait states to the optimum value.  It also enables the cacheability for
    the K0 segment.  It could has side effects of possibly alter the pre-fetch
    buffer and cache.  It sets the RAM wait states to 0.  Other than
    the SYS_FREQ, this takes these parameters.  The top 3 may be '|'ed
    together:
    
    SYS_CFG_WAIT_STATES (configures flash wait states from system clock)
    SYS_CFG_PB_BUS (configures the PB bus from the system clock)
    SYS_CFG_PCACHE (configures the pCache if used)
    SYS_CFG_ALL (configures the flash wait states, PB bus, and pCache)*/

    /* TODO Add user clock/system configuration code if appropriate.  */
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL); 

    /* Initialize I/O and Peripherals for application */
    InitApp();

    /*Configure Multivector Interrupt Mode.  Using Single Vector Mode
    is expensive from a timing perspective, so most applications
    should probably not use a Single Vector Mode*/
    // Configure UART2 RX Interrupt
    INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0);

    // configure for multi-vectored mode
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

    // enable interrupts
    INTEnableInterrupts();


    /* TODO <INSERT USER APPLICATION CODE HERE> */
    //Open UART2
    OpenUART2(UART_EN, UART_BRGH_FOUR|UART_RX_ENABLE | UART_TX_ENABLE, 21);

    //Open SPI 1 channel
    PORTBbits.RB11 = 1;
    OpenSPI1( SPI_MODE8_ON | MASTER_ENABLE_ON | SEC_PRESCAL_1_1 | PRI_PRESCAL_1_1 | FRAME_ENABLE_OFF | CLK_POL_ACTIVE_HIGH | ENABLE_SDO_PIN , SPI_ENABLE );
    SPI1BRG=39;
    initRadio();
    setTXAddress("UNIT2");
    setRXAddress(0,"UNIT1");
    char temp;
    char text[6];
    text[0]='H';
    text[1]='e';
    text[2]='l';
    text[3]='l';
    text[4]='o';
    text[5]='!';
    while(1)
    {
        setTransmitter();
        PORTBbits.RB11 = 0;
        DelayMs(20);
        transmitData(&text[0],6);
        printf("Hello world! \r\n");
        PORTBbits.RB11 = 1;
        DelayMs(20);
    }
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
int main(int argc, char**argv)
{
	int i;
	int fd = 0;
	uint16_t trial = 0;
	char* portPath = NULL;
	char* rx_addressString = NULL;
	char* tx_addressString = NULL;

	printf("> Simple message listener for tea-bootloader compatible nodes\n");        
	
	/*-----------------------------------------------------------------------*/
	
	if(argc == 4)
	{
		portPath = argv[1];		
		rx_addressString = argv[2];
		sscanf(rx_addressString,"%X:%X:%X:%X:%X",rx_addressBuffer,rx_addressBuffer+1,rx_addressBuffer+2,rx_addressBuffer+3,rx_addressBuffer+4);
		tx_addressString = argv[3];
		sscanf(tx_addressString,"%X:%X:%X:%X:%X",tx_addressBuffer,tx_addressBuffer+1,tx_addressBuffer+2,tx_addressBuffer+3,tx_addressBuffer+4);
	}
	else
	{
		printf("> Argument parsing error!\n");
		printf("> Usage: [port path] [dongle RX address] [node RX address]\n");
		printf("> Example: ./main /dev/tty.usbserial-A900cbrd 0xE7:0xE7:0xE7:0xE7:0x00 0xD7:0xD7:0xD7:0xD7:0xD7\n");
		return 0;
	}			

	/*-----------------------------------------------------------------------*/	   

    fd = serialport_init(portPath,115200,'n');

    if(fd < 0)
    {
        printf("[err]: Connection error.\n");
        return 0;
    }
    else
   	{
        printf("> Conection OK.\n");
        serialport_flush(fd);
        printf("> Serial port flush OK.\n");   

        if(loopbackTest(fd) != 0)
        {
        	printf("> Loopback test failed!\r\n");
        	return 0;
        }
        else
        {        	
        	uint8_t version = getVersion(fd);
        	printf("> Dongle version: %d.%d\r\n",(version>>4),(version&0x0F));
        }                    
    }   

    printf("> Setting the TX address ...\n");
    setTXAddress(fd,tx_addressBuffer);

    printf("> Setting the RX address ...\n");
    setRXAddress(fd,rx_addressBuffer);

    while(1)
    {
    	uint8_t thisBuffer[1024];
    	char sendBuffer[256];
    	uint8_t len;
    	int temp;
    	float realval;
    	if(getRxFifoCount(fd))
    	{
			len = getRxFifoCount(fd);
			printf("> ---------------------------------------------------------------------------\n");
			printf("> New message!\n");
			printf("> Length: %d\n",len);
			pullDataFromFifo(fd,len,thisBuffer);

			hexDump("> Dump",thisBuffer,len);			

			temp = (thisBuffer[0]<<8)+thisBuffer[1];
			realval  = ((float)temp * 1100.0) / 1024.0;              
			realval -= 500;
			realval /= 10.0;

			printf("> Raw: %d\n",temp);
			printf("> Readout: %f\n",realval);
			sprintf(sendBuffer,"./phant_client.rb %f",realval);
			system(sendBuffer);
			printf("> Phant.io send process done.\n");
    	}
    }


}