Esempio n. 1
0
// gives a response of the form CK_UP 5:OK/18
static inline void respond( char* p_command, u16 p_page, char* p_response ) {
  uartPutString( p_command );
  uartPutChar( ' ' );

  itoa( p_page, s_tmpBuffer, 10 );
  uartPutString( s_tmpBuffer );
  uartPutChar( ':' );

  uartPutString( p_response );
  uartPutChar( '/' );

  u16 bufferRemaining = uartReceiveBufferRemaining();
  itoa( bufferRemaining, s_tmpBuffer, 10 );
  uartPutStringCRLF( s_tmpBuffer );
}
Esempio n. 2
0
int
main(void)
{
	struct ds1307_t rtc_tm;

	static const char infostring[] PROGMEM = "Demo - DS1307 RTC\r\n";
	char buffer[BUFFER_SIZE];

	uartInit(BAUDRATE);
	i2cInit(I2C_STD_MODE);
	sei();

	ds1307Init();
	ds1307SetTime(SYS_HOUR, SYS_MINS, SYS_SECS);
	ds1307SetDate(SYS_DAY, SYS_MONTH, SYS_YEAR);

	uartPutString_P(infostring);

	while (1) {
		/* Read Current Time from DS1307 and output to UART */
		ds1307GetTime(&rtc_tm);
		sprintf(buffer, "RTC: [%02d:%02d:%02d] - [%02d.%02d.%02d]\r\n",
		    rtc_tm.hours, rtc_tm.minutes, rtc_tm.seconds, rtc_tm.day,
		    rtc_tm.month, rtc_tm.year);
		uartPutString(buffer);
		_delay_ms(1000);
	}

	/* never reached */
	return (0);
}
Esempio n. 3
0
/*------------------------------------------------------------------------------
 * Main Program
 *----------------------------------------------------------------------------*/
int main(void) {
	uartInit(12);		/* baudrate 38400 */
	sei();
	MCP_init();
	
	uartPutString("MCP2515 CAN Test\n");
	
	/* request configuration mode */
	MCP_WRITE_B(CANCTRL, CANCTRL_REQOP, REQOP_CONFIG);
	
	/* configure SJW and Tq duration */
	MCP_WRITE_B(CNF1, CNF1_SJW, 4-1); 	/* SJW = X-1 [Tq] */
	MCP_WRITE_B(CNF1, CNF1_BRP, 0);		/* Tq = 2*(X+1)/FOSC [s] */
	
	/* configure phase seg1 and propseg */
	MCP_WRITE_B(CNF2, CNF2_BTLMODE, 1);
	MCP_WRITE_B(CNF2, CNF2_SAM, 1);
	MCP_WRITE_B(CNF2, CNF2_PHSEG1, 4-1);	/* PHSEG1 = X-1 [Tq] */
	MCP_WRITE_B(CNF2, CNF2_PRSEG, 4-1);		/* PRSEG = X-1 [Tq] */
	
	/* configure phase seg2 and wakeup filter */
	MCP_WRITE_B(CNF3, CNF3_WAKFIL, 1);
	MCP_WRITE_B(CNF3, CNF3_PHSEG2, 4-1);	/* PHSEG2 = X-1 [Tq] */
	
	/* configure interrupts */
	MCP_WRITE_R(CANINTE, 0);
	
	// Mark all filter bits as don't care:
    mcp_write_can_id(RXMnSIDH(0), 1, 0);
    mcp_write_can_id(RXMnSIDH(1), 1, 0);
    // Anyway, set all filters to 0:
    mcp_write_can_id(RXF0SIDH, 0, 0);
    mcp_write_can_id(RXF1SIDH, 0, 0);
    mcp_write_can_id(RXF2SIDH, 0, 0);
    mcp_write_can_id(RXF3SIDH, 0, 0);
    mcp_write_can_id(RXF4SIDH, 0, 0);
    mcp_write_can_id(RXF5SIDH, 0, 0);
	
	/* request loopback mode */
	MCP_WRITE_B(CANCTRL, CANCTRL_REQOP, REQOP_LOOPBACK);
	
	uint8_t tmp = MCP_read(CANCTRL);
	uartPutString("CANCTRL = ");
	uartPutUInt8(tmp, 2);
	uartPutString("\n");
	tmp = MCP_read(CANSTAT);
	uartPutString("CANSTAT = ");
	uartPutUInt8(tmp, 2);
	uartPutString("\n");
	tmp = MCP_read(CNF1);
	uartPutString("CNF1 = ");
	uartPutUInt8(tmp, 2);
	uartPutString("\n");
	tmp = MCP_read(CNF2);
	uartPutString("CNF2 = ");
	uartPutUInt8(tmp, 2);
	uartPutString("\n");
	tmp = MCP_read(CNF3);
	uartPutString("CNF3 = ");
	uartPutUInt8(tmp, 2);
	uartPutString("\n");
	tmp = MCP_read(CANINTE);
	uartPutString("CANINTE = ");
	uartPutUInt8(tmp, 2);
	uartPutString("\n");
	
	/* main loop */
	while(1) {
		/* do nothing */
		
	}
}
Esempio n. 4
0
File: main.c Progetto: ChakChel/Ix
/**
 * @fn      int main( void );
 * @brief   Point d'entrée du programme
 * @return
 */
int main(void){

    char ordre[50];
    char cons[10];
    int ref=18;
    int pwm=0;
    int fil=0;
    char BUF_RX[50];
    char BUF_TX[1000];
    int aux1;
    char *data_IL, *data_VO, *data_VI;

    //Optimisation du fonctionnement du CPU
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    init();
    intConfig();







    uartPutString(" ****** * * ******* ******     ***    ******    **    ****** ***   ***\r\n");
    uartPutString("*  **** * * *** *** * *** *   *   *  *  ****   *  *   * **** *  *  * *\r\n");
    uartPutString("* *     * *   * *   * *** *  *  *  * * *      * ** *  * *    * * * * *\r\n");
    uartPutString("* *     * *   * *   * ** *   * *** * * *     * **** * * ***  * ** ** *\r\n");
    uartPutString("* *     * *   * *   * * * *  *  *  * * *     * *  * * * *    * * * * *\r\n");
    uartPutString("*  **** * *   * *   * *  * *  *   *  *  **** * *  * * * **** * *  *  *\r\n");
    uartPutString(" ****** * *   * *   * *   * *  ***    ****** * *  * * ****** * *   * *\r\n");
    uartPutString("citroen corp. with Ixchel Intelligent Systems patnership\r\n");
    strcpy(BUF_TX,"boost converter module interface. Enter help to know the supported commands\r\nboost:~# \0");
    uartPutString(BUF_TX);

    while (1) {;

        if (flagTraitement) {
            flagTraitement = 0;
            // Acquisition
            ads7885Pic32Read( CHN_SPI, data_IL, data_VO, data_VI );
            mesure[0][pMesure]=atoi(data_IL);
            mesure[1][pMesure]=atoi(data_VO);
            mesure[2][pMesure]=atoi(data_VI);

            pMesure++;
            if (pMesure >= TAILLE_MESURE)
                pMesure = 0;
          gpioLed();
            // Calcul
            commande[pCommande] = fTransfert(consigne, mesure[0], commande);
//
//            // Commande
//            pwmSet(commande[pCommande]);
//            pCommande++;
//            if (pCommande >= TAILLE_COMMANDE)
//                pCommande = 0;*/
            if (flagAuto == 0){
                pwmSet(pwm);
            }
        }

        if (flagReception) {

            uartPutChar(aux);

            if(aux=='\b'){
                if(i>0) i--;
            }
            else if(aux!='\r'){
                BUF_RX[i]=aux;
                i++;
            }
            else
            {
                BUF_RX[i]='\0';
                uartPutChar('\r');
                uartPutChar('\n');
                i=0;

                // On reçoit l'ordre
                while(BUF_RX[i]!=' '){
                    ordre[i]=BUF_RX[i];
                    i++;
                }
                ordre[i]='\0';
                i++;
                int j=0;
                while(BUF_RX[i]!='\0'){
                    cons[j]=BUF_RX[i];
                    i++;
                    j++;
                }
                cons[j]='\0';

                i=0;

                if(strcmp(ordre, "auto")==0){
                    strcpy(BUF_TX,"automatic mode is running\n\rchange voltage reference value with ref command\n\r");
                    flagAuto = 1;
                    ref=18;
                }
                else if(strcmp(ordre, "manual")==0){
                    strcpy(BUF_TX,"pwm mode is running\n\rchange duty cycle value with pwm command\n\r");
                    flagAuto = 0;
                    pwm=0;
                }
                else if(strcmp(ordre, "ref")==0){

                    sscanf(cons,"%i",&aux1);

                    if((aux1!=18)&&(aux1!=24)&&(aux1!=30)&&(aux1!=36)){
                        strcpy(BUF_TX,"error: failed value\n\r");
                    }
                    else {
                        ref=aux1;
                        sprintf(BUF_TX,"output voltage value is updated to %d\n\r",ref);
                    }
                }
                else if(strcmp(ordre, "pwm")==0){

                    sscanf(cons,"%i",&aux1);

                    if((aux1>=0)&&(aux1<=100)&&(strcmp(cons, "")!=0)){
                        sprintf(BUF_TX,"the duty cycle value is updated to %d%\n\r",aux1);
                        pwm= (aux1*T3_TICK)/100;
                    }
                    else {
                        strcpy(BUF_TX,"error: failed value\n\r");
                    }
                }
                else if(strcmp(ordre, "means")==0);//{
                    //                break;
                //            }
                else if(strcmp(ordre, "can")==0){
                    uartPutString("can controller configuration :\n\r");
                    sprintf(BUF_TX,"bus speed 250000 bps\n\r");
                    uartPutString(BUF_TX);
                    sprintf(BUF_TX,"data length 8 bytes\n\r");
                    uartPutString(BUF_TX);
                    sprintf(BUF_TX,"filter 0x%03X\n\r",fil);
                    uartPutString(BUF_TX);
                    strcpy(BUF_TX,"filter mask 0xFFF\n\r");
                }
                else if(strcmp(ordre, "filter")==0){
                    if(strlen(cons)==3){
                        sscanf(cons,"%X",&fil);
                        sprintf(BUF_TX,"can filter value is updated to 0x%03X\n\r",fil);
                    }
                    else {
                        sprintf(BUF_TX,"error: failed value size= %d\n\r",strlen(cons));
                    }
                }
                else if(strcmp(ordre, "help")==0){
                    uartPutString("auto         start automatic mode and stop manual mode\r\n");
                    uartPutString("             update voltage reference value with ref command\r\n");
                    uartPutString("manual       start manual mode and stop automatic mode\r\n");
                    uartPutString("             update duty cycle value with pwm command\r\n");
                    uartPutString("ref          update output voltage reference value\r\n");
                    uartPutString("pwm          update duty cycle value\r\n");
                    uartPutString("means        print currents analog values\r\n");
                    uartPutString("can          print can controller configuration\r\n");
                    uartPutString("filter       update can filter\r\n");
                    sprintf(BUF_TX,"help         print supported commands\r\n");
                }
                else if(strcmp(ordre, "")==0){
                    strcpy(BUF_TX,"\r\n");
                }
                else{
                    strcpy(BUF_TX,"error: enter help to know the supported commands\n\r");
                }
                uartPutString(BUF_TX);
                strcpy(BUF_TX,"boost:~# \0");
                uartPutString(BUF_TX);
            }

            flagReception = 0;

            if (consigne < 0)
            consigne = 0;
            else if (consigne > 262143)
            consigne = 262143;
        }
    }

    close();
}
Esempio n. 5
0
int main(void) {
  u08 c;
  char buffer[7];
  int  num=1;
  bool isFlowControlOn = true;
  bool isHexModeOn = false;

  ledsSet(1);
  ledsInit();
  
  ledsSet(2);
  uartInit( UART_BAUD_SELECT( 9600, F_CPU ) );
  
  ledsSet(3);
  uartFlowControlOn( true );
  
  ledsSet(4);
  uartPutString("String stored in SRAM\n");
  
  ledsSet(5);    
  uartPutString("String stored in FLASH\n");
  
  ledsSet(6);        
  itoa( num, buffer, 10);       // convert interger into string (decimal format)         
  uartPutString(buffer);        // and transmit string to UART
  uartPutString( "\n" );
  
  ledsSet(7);    
  //while ( !uartIsCharAvailable() ) {
    //do nothing
  //}
  //c = uartBlockingGetChar();
  uartPutString( "You pressed: " );
  //uartPutChar( c );
  uartPutString( "\n" );
  
  for(;;) {
    ledsSet(11);    
    c = uartBlockingGetChar();
    //_delay_ms( 100 );
    ledsSet(12);    
    
    if ( c == 'V' ) {
      uartPutString( "testSerial: " );
      uartPutString( __DATE__ );
      uartPutString( " " );
      uartPutString( __TIME__ );
      uartPutString( "\n" );
    } else if ( c == 'B' ) {
      MCUCR = _BV(IVCE);
      MCUCR = _BV(IVSEL);               //move interruptvectors to the boot sector sector
      asm volatile("jmp 0x3800");
    } else if ( c == 'F' ) {
Esempio n. 6
0
File: main.c Progetto: ChakChel/Ix
/**
 * @fn      void dialogueUART( void *pvParameters )
 * @brief   Reçoit des ordres depuis le port série
 * @brief   Se réveille lors de l'arrivée de données sur l'UART
 * @param   pvParameters  Pointeur sur un paramètre passé à la tâche
 */
void dialogueUART( void *pvParameters ) {

    int i = 0;              // compteurs de boucle
    int j;                  // compteurs de boucle
    char BUF_RX[50];        // buffer de reception via l'uart
    char BUF_TX[100];      // buffer de transmission via l'uart
    int aux1;               // variable tampon pour vérifier la validité avant de mettre dans pwm
    char ordre[50];         // variable tampon pour récupérer l'ordre envoyé par l'uart
    char cons[10];          // variable tampon pour récupérer la consigne suivant l'ordre

    // boucle d'excecution
    for(;;) {

        vTaskSuspend(xDialogueUARTHandle);

        if (aux == 0x1B && i == 0) {
            i = strlen(ordre)+ 1 + strlen(cons) + 1;
            sprintf (BUF_TX,"%s %s\r\n", ordre, cons);
            uartPutString(BUF_RX);
        } else {
            uartPutChar(aux);         // renvoie d'aquittement

            // prise en compte de correction
            if (aux == '\b') {
                if(i > 0) {
                    i--;
                    uartPutChar(' ');
                    uartPutChar('\b');
                }

            //recupération de l'ordre caractere par caractere tant qu'il n'y a pas de retour chariot
            } else if (aux != '\r') {
                BUF_RX[i] = aux;
                i++;
            } else {    // si aux = \r
                BUF_RX[i] = '\0';
                uartPutChar('\r');
                uartPutChar('\n');
                i = 0;

                // Séparation ordre-consigne
                while ((BUF_RX[i] != ' ')&&(BUF_RX[i] != '\0')) {
                    ordre[i] = BUF_RX[i];
                    i++;
                }
                ordre[i] = '\0';      // transformation de ordre en string
                j = 0;
                while (BUF_RX[i] != '\0') {
                    cons[j] = BUF_RX[i];
                    i++;
                    j++;
                }
                cons[j] = '\0';       // transformation de ordre en string
                i = 0;

                if(strcmp(ordre, "auto") == 0){
                    strcpy(BUF_TX,"automatic mode is running\n\rchange voltage reference value with ref command\n\r");
                    flagAuto = TRUE;
                    ref = 180;

                } else if (strcmp(ordre, "manual") == 0) {
                    strcpy(BUF_TX,"pwm mode is running\n\rchange duty cycle value with pwm command\n\r");
                    flagAuto = FALSE;
                    pwm = 0;

                } else if (strcmp(ordre, "ref") == 0) {
                    sscanf(cons,"%i",&aux1);
					if (flagAuto == FALSE)
                    	sprintf(BUF_TX,"manual mode is running, write manual before sending a new value for ref\n\r");
                    else if ((aux1 != 18)&&(aux1 != 24)&&(aux1 != 30)&&(aux1 != 36))
                        strcpy(BUF_TX,"error: failed value\n\r");
                    else {
                        ref = aux1*10;
                        sprintf(BUF_TX,"output voltage value is updated to %d\n\r",ref);
                    }

                } else if (strcmp(ordre, "pwm") == 0){
                    sscanf(cons,"%i",&aux1);
                    if (flagAuto == TRUE)
                        sprintf(BUF_TX,"automatic mode is running, write manual before sending a new value for pwm\n\r");
                    else if ((aux1 >= 0) && (aux1 <= 100) && (strcmp(cons, "") != 0)) {
                        sprintf(BUF_TX,"the duty cycle value is updated to %d%\n\r",aux1);
                        pwm = aux1;
                    } else
                        strcpy(BUF_TX,"error: failed value\n\r");

                } else if (strcmp(ordre, "meas") == 0) {
                    sprintf(BUF_TX,"Courant d'entree : IL = %d A\n\r",mesure[0][pMesure]);
                    uartPutString(BUF_TX);
                    sprintf(BUF_TX,"Tension d'entree : VI = %d V\n\r",mesure[2][pMesure]);
                    uartPutString(BUF_TX);
                    sprintf(BUF_TX,"Tension de sortie : VO = %d V\n\r",mesure[1][pMesure]);
//                    uartPutString(BUF_TX);

                } else if(strcmp(ordre, "can") == 0) {
                    uartPutString("can controller configuration :\n\r");
                    sprintf(BUF_TX,"bus speed 250000 bps\n\r");
                    uartPutString(BUF_TX);
                    sprintf(BUF_TX,"data length 8 bytes\n\r");
                    uartPutString(BUF_TX);
                    sprintf(BUF_TX,"filter 0x%03X\n\r",fil);
                    uartPutString(BUF_TX);
                    strcpy(BUF_TX,"filter mask 0x7FF\n\r");

                } else if (strcmp(ordre, "filter") == 0) {
                    if(strlen(cons) == 3) {
                        sscanf(cons,"%X",&fil);
                        sprintf(BUF_TX,"can filter value is updated to \
                        0x%03X\n\r",fil);
                    } else
                        sprintf(BUF_TX,"error: failed value size= %d\n\r",strlen(cons));

                } else if (strcmp(ordre, "help") == 0) {
                    uartPutString("auto         start automatic mode and stop manual mode\r\n");
                    uartPutString("             update voltage reference value with ref command\r\n");
                    uartPutString("manual       start manual mode and stop automatic mode\r\n");
                    uartPutString("             update duty cycle value with pwm command\r\n");
                    uartPutString("ref          update output voltage reference value\r\n");
                    uartPutString("pwm          update duty cycle value\r\n");
                    uartPutString("meas         print currents analog values\r\n");
                    uartPutString("can          print can controller configuration\r\n");
                    uartPutString("filter       update can filter\r\n");
                    sprintf(BUF_TX,"help        print supported commands\r\n");
                }

                else if (strcmp(ordre, "") == 0)
                    strcpy(BUF_TX,"\r\n");

                else
                    strcpy(BUF_TX,"error: enter help to know the supported \
                    commands\n\r");

                uartPutString(BUF_TX);
                strcpy(BUF_TX,"boost:~# \0");
                uartPutString(BUF_TX);
            }
Esempio n. 7
0
static inline void uartPutStringCRLF( char* p_str ) {
  uartPutString( p_str );
  uartPutString( "\r\n" );
}