Ejemplo n.º 1
0
// Initialise radio (in rx mode)
void nrf24l01plus_init(void)
{
    int i;
    
    Init_SPI(); // Enable SPI
    
    PIO_Clear(&CE);
    PIO_Set(&CSN);    
    
    for(i=0; i<32; i++)
        tx_buf[i] = 0; // init buffer
    
    PIO_Clear(&CE);    
    
    SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);    // Writes TX_Address to nRF24L01
    SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // RX_Addr0 same as TX_Adr

    SPI_RW_Reg(WRITE_REG + EN_AA, 0x00);      // Disable Auto.Ack
    SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);  // Enable Pipe0
    SPI_RW_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH); // Select same RX payload width as TX Payload width
    //SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a);       // 500us + 86us, 10 retransmissions. (not needed - no auto ack)
    SPI_RW_Reg(WRITE_REG + RF_CH, RF_CHANNEL);        // Select RF channel
    SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);   // TX_PWR:0dBm, Datarate:1Mbps
    SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);     // Set PWR_UP bit, enable CRC(2 unsigned chars) & Prim:TX. MAX_RT & TX_DS enabled..
    
    PIO_Set(&CE);
}
Ejemplo n.º 2
0
int main(void) {
    if (SysTick_Config(SystemCoreClock / 1000)) {
        while (1) {};
    }
    Init_GPIO();
    Init_SPI();
    Init_RNG();
    Init_LCD();

    int counter=1;
    int counter2 =0;
    int x = 0;
    int y = 0;
    DrawFillRectangle(1,1,128,160,0xFFFFFF);
    for ( x = 160; x > 0; x-- )
        for ( y = 1; y <= 84; y++ )
            DrawFillRectangle(y+22, x, 1, 1, Image[(y-1)*160+161-x]-0x010101);
    while(1) {


        //DrawFillRectangle(RNG->DR%128,RNG->DR%160,RNG->DR%128,RNG->DR%160,RNG->DR);
        /*if ( counter2 == 60000 ) {
            DrawFillRectangle(counter-1, counter-1, 20, 20, 0x000000);
            DrawFillRectangle(counter, counter, 20, 20, RNG->DR);
            //DrawFillRectangle(1,1,128,160,0x00000);
            counter+=1;
            counter2=0;
        }
        counter2+=1;
        if ( counter == 108 ) {
            DrawFillRectangle(1,1,128,160,0x00000);
            counter = 0;
        }*/
        /*GPIOD->ODR^=GreenLed;
        Delay(1);
        GPIOD->ODR^=OrangeLed;
        Delay(1);
        GPIOD->ODR^=RedLed;
        Delay(1);
        GPIOD->ODR^=BlueLed;
        Delay(1);*/
    }
    return 0;
}
Ejemplo n.º 3
0
/////////////////////////////////////////////////////////
/// Function: main
///
/// <summary></summary>
///
/// <returns>Nothing</returns>
/////////////////////////////////////////////////////////
int main ()
{
	int x = 0;
	int y = 0;
	int z = 0;

	initPortE();

	PEOUT = 0xFF; // for CS cuz it needs high for off - 0xFF;

	x = init_uart(_UART0,_DEFFREQ,_DEFBAUD); 
	if(x == 0)
		printf("Hello UART0\n"); // Write to _UART0

    Init_SPI();      // Master, Phase = 1, Clock polarity = 0
//	SPI_Init(0x8000, MASTER, TRUE, FALSE);      // Master, Phase = 1, Clock polarity = 0

	if(x == 0)
		printf("x, y, z\n");
	while(1)
	{
		PEOUT = 0xFF;
		test_SPI();
		PEOUT = 0xFF;
	    // TODO : cycle through each of the accelerometers and capture
		// the data
/*		int pin = 0x80; // Starts at PE7
		int i = 0;
		for(i = 0; i < g_NumAccel; i++)
		{
			PEOUT ^= pin;
			readData();
			PEOUT = 0xFF;
			pin = pin >> 1;
		}*/
	}
	return 0;
}
Ejemplo n.º 4
0
void main(void)
{
	unsigned char i=0;
	unsigned char status;
	unsigned char str[MAX_LEN];
	unsigned char RC_size;
	unsigned char blockAddr;
	unsigned char mynum[20];
	unsigned char serNum[7];

	uint8_t RCV;
	int resulta=0;
	int fd;
	int a=0;



	fd=Init_SPI("/dev/spidev0.0");
	setup_io();

	SET_INPUT(25);
	SET_OUTPUT(25);

	ApiInit(fd);
	MFRC522_Init();

	a=Read_MFRC522(VersionReg);
	printf("MFRC Version Read %02X \r\n",a);


	//	for(a=0;a<10;a++)
	//	{
	//		RCV=Read_MFRC522(VersionReg);
	//		//RCV=SPI_transfer(fd,a);
	//		printf("RCV %02X \r\n",RCV);
	//		SET_BIT(25);
	//        sleep(1);
	//        CLR_BIT(25);
	//        sleep(1);
	//	}
	while(1)
	{
		status = MFRC522_Request(PICC_REQIDL, str);
		if(resulta==status){

		}else{
			resulta=status;
		}


		if (status == MI_OK)
		{
			mifare_tag_type(str);
			//usleep(1000);
		}

		status = MFRC522_Anticoll(str);
		memcpy(serNum, str,5);
		if (status == MI_OK)
		{
			printf("UID :");
			for(i=0;i<5;i++)
			{
				printf("[");
				printf("%02X",serNum[i]);
				printf("]");
			}
			printf("\n");
			//usleep(1000);
		}

		RC_size=MFRC522_SelectTag(serNum);
		if(RC_size !=0)
		{

			printf("Select_OK Size %02d \n",RC_size);
			puts("");
			puts("");

		}

	}

	close(fd);

}
Ejemplo n.º 5
0
int main(void)
{

	short i,j;
	
// Configure Oscillator to operate the device at 40Mhz
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 8M*40/(2*2)=80Mhz for 8M input clock
	PLLFBD=38;					// M=40
	CLKDIVbits.PLLPOST=0;		// N1=2
	CLKDIVbits.PLLPRE=0;		// N2=2
	OSCTUN=0;					// Tune FRC oscillator, if FRC is used

// Disable Watch Dog Timer
	RCONbits.SWDTEN=0;

// Clock switching to incorporate PLL
	__builtin_write_OSCCONH(0x03);		// Initiate Clock Switch to Primary
													// Oscillator with PLL (NOSC=0b011)
	__builtin_write_OSCCONL(0x01);		// Start clock switching
	while (OSCCONbits.COSC != 0b011);	// Wait for Clock switch to occur	

// Wait for PLL to lock
	while(OSCCONbits.LOCK!=1) {};


	TRISA = 0x0;				// set to all outputs

	// setup the SPI1 port
	// setup the I/O pins properly (SDI1 as input, SDO1 as output, RG3 as output)
	PORTG = 0xFFFF;
	TRISG = 0x5F5F;
	PORTF = 0x0;
	TRISF = 0x5F;
	AD1PCFGLbits.PCFG2 = 1;		// set the RB0 pin to Digital Mode (all others to analog) 
	TRISF = 0x0080;				// set PORTF to output except for SDI1
	
	
	

	while(1)
	{
		//demonstrate the SPI peripheral in Master Mode CKE = 0, CKP = 0
	
			Init_SPI();
	
		for (i=0;i<255;i++)
			{
				write_SPI1(i);
				delay();
			} 

		for (i=0;i<255;i++)
			{
				write_SPI2(i);
				delay();
			} 

		for (i=0;i<255;i++)
			{
				write_SPI1(i);
				delay();
				write_SPI2(i);
				delay();
			} 


	}
}
Ejemplo n.º 6
0
int main(void) {
    /* Ledstrips inits */
    /* W5100 defines */
    unsigned char sockstat;
    unsigned int rsize;
    char radiostat0[10], radiostat1[10];
    int postidx, getidx;
    /* Initial variable used */
    sockreg = 0;
    tempvalue = 0;
    ledmode = 0;

    Init_timer1();
    Init_timers();
    /*Init_shift();*/
    OSCTUN = 21;
    PLLFBD = 38; /* M=40 */
    CLKDIVbits.PLLPOST = 0; /* N1=2 */
    CLKDIVbits.PLLPRE = 0; /* N2=2 */
   /* Eraseleds();*/
    /* even ledstrips have to be mirrored */
   /* Mirror(patt); */

    /* LCD inits */
    Init_mcp();
    Init_LCD();
    Write_LCD(startup);

    /* W5100 inits */
    Init_pin_SPI();
    Init_SPI();
    W5100_Init(gtw_addr,mac_addr,sub_mask,ip_addr);
    T_SPI_CS;
    SPI_CS = 1;

    Init_UART();

    for (;;) {

        sockstat = SPI_Read(S0_SR);
        switch (sockstat) {
            case SOCK_CLOSED:
                if (socket(sockreg, MR_TCP, TCP_PORT) > 0) {
                    /* Listen to Socket 0 */
                    if (listen(sockreg) <= 0)
                        Delayms(1);
                }
                break;

            case SOCK_ESTABLISHED:
                /* Get the client request size */
                rsize = recv_size();
                if (rsize > 0) {
                    /* Now read the client Request */
                    if (recv(sockreg, buf, rsize) <= 0)
                        break;

                    Putstr(buf);
/*                    printf("%s",buf);*/
                    /* Check the Request Header */
                    getidx = strindex((char *) buf, "GET /");
                    postidx = strindex((char *) buf, "POST /");

                     if (getidx >= 0 || postidx >= 0) {

                        /* Now check the Radio Button for POST request */
                        if (postidx >= 0) {
                            if (strindex((char *) buf, "uBoard new color") > 0)
                                ledmode++;
                        }


            /* Create the HTTP Response	Header */
	    strncpy((char *)buf,("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
                                "<body style=\"background-color:FFFFFF;\">\r\n"),96);

	    strcat((char *)buf,("[\n"
                                 "   {\n"
                                 "       \"id\": \"1\",\n"
                                 "       \"name\": \"uBoard webboard\",\n"
                                 "       \"ipaddr\": \"192.168.0.102\",\n"
                                 "       \"subnetmask\": \"255.255.255.0\",\n"
                                 "       \"gateway\": \"192.168.0.1\",\n"
                                 "       \"adjustSpeedOfPattern\": \"int\",\n"
                                 "       \"turnLedsOnOff\": \"boolean\"\n"
                                 "   }\n"
                                 "]\n"));




            /* Now Send the HTTP Response */
	    if (send(sockreg,buf,strlen((char *)buf)) <= 0) break;

            /* TODO: add status */
            LCD_Clear();
            LCD_PutByte(ledmode);
	    if (ledmode == 1) {
	      strncpy(radiostat0,"",0);
	      strncpy(radiostat1,("checked"),7);
	    } else {
	      strncpy(radiostat0,("checked"),7);
	      strncpy(radiostat1,"",0);
	    }

            /* Create the HTTP Radio Button Response */
	    strncpy((char *)buf,("<p><input type=\"radio\" name=\"radio\" value=\"0\" "),52);
	    strcat((char *)buf,radiostat0);
	    strcat((char *)buf,(">Turn off\r\n"));
	    strcat((char *)buf,("<br><input type=\"radio\" name=\"radio\" value=\"1\" "));
	    strcat((char *)buf,radiostat1);
	    strcat((char *)buf,(">Lounge mode\r\n"));
 	    strcat((char *)buf,("</strong><p>\r\n"));
	    strcat((char *)buf,("<input type=\"submit\">\r\n"));
	    strcat((char *)buf,("</form></span></body></html>\r\n"));            /* Now Send the HTTP Remaining Response */
	    if (send(sockreg,buf,strlen((char *)buf)) <= 0)
                break;


                    } /* Disconnect the socket */
                    disconnect(sockreg);
                } else
                    Delayms(1); /* Wait for request */
                break;

            case SOCK_FIN_WAIT:
            case SOCK_CLOSING:
            case SOCK_TIME_WAIT:
            case SOCK_CLOSE_WAIT:
            case SOCK_LAST_ACK:
                /* Force to close the socket */
                close(sockreg);

                break;
        }
    }
    return 0;
}