Пример #1
0
void Components_Init(void)
{
    /*! DMA_controller Auto initialization start */
    EDMA_DRV_Init(&DMA_controller_State,&DMA_controller_InitConfig0);
    /*! DMA_controller Auto initialization end */


    /*! OLED_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_OLED_SPI, &OLED_SPI_MasterState, &OLED_SPI_MasterConfig, &OLED_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_OLED_SPI, &OLED_SPI_BusConfig, &OLED_SPI_calculatedBaudRate);
    /*! OLED_SPI Auto initialization end */

    /*! FLASH_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_FLASH_SPI, &FLASH_SPI_MasterState, &FLASH_SPI_MasterConfig, &FLASH_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_FLASH_SPI, &FLASH_SPI_BusConfig, &FLASH_SPI_calculatedBaudRate);
    /*! FLASH_SPI Auto initialization end */

    /*! GPIO Auto initialization start */
    GPIO_DRV_Init(NULL,NULL);
    /*! GPIO Auto initialization end */

    /*! KW40_UART Auto initialization start */
    UART_DRV_Init(FSL_KW40_UART,&KW40_UART_State,&KW40_UART_InitConfig0);
    /*! KW40_UART Auto initialization end */
    /*! DEBUG_UART Auto initialization start */
    UART_DRV_Init(FSL_DEBUG_UART,&DEBUG_UART_State,&DEBUG_UART_InitConfig0);
    /*! DEBUG_UART Auto initialization end */
    /*! FS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_FS_I2C, &FS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_FS_I2C, &FS_I2C_MasterConfig);
    /*! FS_I2C Auto initialization end */

    /*! NFS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_NFS_I2C, &NFS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_NFS_I2C, &NFS_I2C_MasterConfig);
    /*! NFS_I2C Auto initialization end */

    /*! PWR_Manager Auto initialization start */
//  POWER_SYS_Init(powerConfigsArr, 2U, NULL , 0U);
    INT_SYS_EnableIRQ(LLWU_IRQn);
    /*! PWR_Manager Auto initialization end */
    /*! CLOCK Auto initialization start */
    RTC_DRV_Init(FSL_CLOCK);
    /*! CLOCK Auto initialization end */

    /*! BATTERY_ADC Auto initialization start */
    ADC16_DRV_Init(FSL_BATTERY_ADC, &BATTERY_ADC_InitConfig);
    ADC16_DRV_ConfigConvChn(FSL_BATTERY_ADC, 0U, &BATTERY_ADC_ChnConfig);
    /*! BATTERY_ADC Auto initialization end */

    /*! sensor_timer Auto initialization start */
    LPTMR_DRV_Init(FSL_SENSOR_TIMER,&sensor_timer_State,&sensor_timer_cfg);
    /*! sensor_timer Auto initialization end */

}
/*==================[external functions definition]==========================*/
extern ciaaDevices_deviceType * ciaaDriverUart_open(char const * path, ciaaDevices_deviceType * device, uint8_t const oflag)
{
   ciaaDriverUart_uartType * uart = device->layer;

   if (kStatus_UART_Success != UART_DRV_Init(uart->instance, &uart->state, &uart->config)) {
      device = NULL;
   }
   return device;
}
Пример #3
0
OSStatus internal_uart_init( mico_uart_t uart, const mico_uart_config_t* config, ring_buffer_t* optional_rx_buffer )
{
#ifndef NO_MICO_RTOS
  mico_rtos_init_semaphore(&uart_interfaces[uart].tx_complete, 1);
  mico_rtos_init_semaphore(&uart_interfaces[uart].rx_complete, 1);
#else
  uart_interfaces[uart].tx_complete = false;
  uart_interfaces[uart].rx_complete = false;
#endif  
  MicoMcuPowerSaveConfig(false);  
    /* Configure the UART TX/RX pins */
    configure_uart_pins(BOARD_APP_UART_INSTANCE);
#if ADD_OS_CODE
#ifndef NO_MICO_RTOS
  if(config->flags & UART_WAKEUP_ENABLE){
    current_uart = uart;
    mico_rtos_init_semaphore( &uart_interfaces[uart].sem_wakeup, 1 );
    mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "UART_WAKEUP", thread_wakeup, 0x100, &current_uart);
  }
#endif 
#endif 
	//OSA_Init();
#ifdef UART_IRQ_APP    
    /****************************************************************/
    uartConfig.baudRate = 115200;
    uartConfig.bitCountPerChar = kUart8BitsPerChar;
    uartConfig.parityMode = kUartParityDisabled;
    uartConfig.stopBitCount = kUartOneStopBit;
    /***************************************************************/
    UART_DRV_Init(BOARD_APP_UART_INSTANCE, &uartState, &uartConfig);
#else
    userConfig_app.chnArbitration = kEDMAChnArbitrationRoundrobin;
    userConfig_app.notHaltOnError = false;

    uartConfig_app.bitCountPerChar = kUart8BitsPerChar;
    uartConfig_app.parityMode = kUartParityDisabled;
    uartConfig_app.stopBitCount = kUartOneStopBit;
    uartConfig_app.baudRate = 115200;

    EDMA_DRV_Init(&state_app, &userConfig_app);    
    UART_DRV_EdmaInit(BOARD_APP_UART_INSTANCE, &uartStateEdma_app, &uartConfig_app); 
    INT_SYS_EnableIRQ(g_uartRxTxIrqId[BOARD_APP_UART_INSTANCE]);
#endif
#if RING_BUFF_ON 
  if (optional_rx_buffer != NULL)
  {
     //  Note that the ring_buffer should've been initialised first
    uart_interfaces[uart].rx_buffer = optional_rx_buffer;
    uart_interfaces[uart].rx_size   = 0;
    platform_uart_receive_bytes( uart, optional_rx_buffer->buffer, optional_rx_buffer->size, 0 );
  }  
#endif
  MicoMcuPowerSaveConfig(true);  
  return kNoErr;
}
Пример #4
0
void Components_Init(void)
{

  /*! dd_scheduler Auto initialization start */ 
  (void)dd_scheduler_Init();
  /*! dd_scheduler Auto initialization end */                       
  /*! myUART Auto initialization start */
  OSA_InstallIntHandler(UART3_RX_TX_IRQn, myUART_IRQHandler);
  UART_DRV_Init(myUART_IDX,&myUART_State,&myUART_InitConfig0);
  UART_DRV_InstallRxCallback(myUART_IDX, myUART_RxCallback, myRxBuff, NULL, true);
  /*! myUART Auto initialization end */
    
}
int main(void)
{
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	long int x;

	char AT[] = "\nAT";
	char rxBuff[10];
	uint32_t byteCountBuff = 0;
    //Initialise the FRDM-KL26Z Board
	hardware_init();
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);

	//Print message to serial terminal
	PRINTF("First Embedded Systems Lab_Aonghus\r\n");
	PRINTF("Type a character and it will be echoed back\r\n\n");
	int i = 0;
	byteCountBuff = sizeof(AT);
    while(1) {
    	//UART_DRV_SendDataBlocking(1, AT, byteCountBuff, 16000u);
    	 while(UART_DRV_ReceiveDataBlocking ( 1, rxBuff, sizeof(rxBuff),16000u) == kStatus_UART_Success )
    	 {
    		 for(i=0;i<sizeof(rxBuff);i++)
    		 PRINTF("%c",rxBuff[i]);
    	 }
    	// if(UART_DRV_GetTransmitStatus (1,sizeof(rxBuff)) == kStatus_UART_Success ){

    	// }


    	for(x=0;x<10000000;x++);
    }
    /* Never leave main */
    return 0;
}
Пример #6
0
int main (void)
{
    /***************************************************************************
     *  RX buffers
     **************************************************************************/
    /*! @param receiveBuff Buffer used to hold received data */
    uint8_t receiveBuff[19] = {0};

    /* Initialize standard SDK demo application pins */
    hardware_init();

    /* Configure the UART TX/RX pins */
    configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);

#ifdef USE_STDIO_FUNCTIONS
    /* Call this function to initialize the console UART.  This function
       enables the use of STDIO functions (printf, scanf, etc.) */
    dbg_uart_init();
    
    /*  Print the initial banner */
    printf("\r\nHello World!\n\n\r");

    while(1)
    {
        /********************************************
         * Main routine that simply echoes received
         * characters forever
         *********************************************/

        /* First, get character.  */
        receiveBuff[0] = getchar();
        
        /* Now echo the received character */
        putchar(receiveBuff[0]);
    }
#else
    /***************************************************************************
     * UART configuration and state structures
     **************************************************************************/
    /*! @param uartConfig UART configuration structure */
    /*! @param uartState UARt state structure which is used internally by the*/
    /*! by the UART driver to keep track of the UART states */
    uart_user_config_t uartConfig;
    uart_state_t uartState;
    
    /***************************************************************************
     *  TX buffers
     **************************************************************************/
    /*! @param sourceBuff Buffer used to hold the string to be transmitted */
    uint8_t sourceBuff[19] = {"\r\nHello World!\n\n\r"};
    
    /* Configure the UART for 115200, 8 data bits, No parity, and one stop bit*/
    uartConfig.baudRate = 115200;
    uartConfig.bitCountPerChar = kUart8BitsPerChar;
    uartConfig.parityMode = kUartParityDisabled;
    uartConfig.stopBitCount = kUartOneStopBit;
    
    /* Must call the OSA Init function to use Communication drivers */
    OSA_Init();
    
    /* Initialize the UART module */
    UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig);
    
    /*  Print the initial banner */
    UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 17, 200);

    while(1)
    {
        /********************************************
         * Main routine that simply echoes received
         * characters forever
         *********************************************/

        /* First, get character.  */
        UART_DRV_ReceiveDataBlocking(BOARD_DEBUG_UART_INSTANCE, receiveBuff, 1, 
                                     OSA_WAIT_FOREVER);

        /* Now, stuff the buffer for the TX side and send the character*/
        sourceBuff[0] = receiveBuff[0];

        /* Now echo the received character */
        UART_DRV_SendDataBlocking(BOARD_DEBUG_UART_INSTANCE, sourceBuff, 1, 
                                  200);
    }
#endif
}
Пример #7
0
/* See fsl_debug_console.h for documentation of this function.*/
debug_console_status_t DbgConsole_Init(
        uint32_t uartInstance, uint32_t baudRate, debug_console_device_type_t device)
{
    if (s_debugConsole.type != kDebugConsoleNone)
    {
        return kStatus_DEBUGCONSOLE_Failed;
    }

    /* Set debug console to initialized to avoid duplicated init operation.*/
    s_debugConsole.type = device;

    /* Switch between different device. */
    switch (device)
    {
#if defined(HW_UART_INSTANCE_COUNT)
        case kDebugConsoleUART:
            {
                /* Declare config sturcuture to initialize a uart instance. */
                uart_user_config_t uartConfig;
                uart_status_t status;


                /* Config the structure. */
                uartConfig.baudRate = baudRate;
                uartConfig.bitCountPerChar = kUart8BitsPerChar;
                uartConfig.parityMode = kUartParityDisabled;
                uartConfig.stopBitCount = kUartOneStopBit;

                /* Init UART device. */
                status = UART_DRV_Init(uartInstance, &s_debugConsole.state.uartState, &uartConfig);

                if ((status != kStatus_UART_Success)&&(status != kStatus_UART_Initialized))
                {
                    s_debugConsole.type = kDebugConsoleNone;
                    return kStatus_DEBUGCONSOLE_Failed;
                }

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.Send = UART_DRV_SendPollBlocking;
                s_debugConsole.ops.Receive = UART_DRV_ReceivePollBlocking;
            }
            break;
#endif
#if 0
#if defined(HW_LPUART_INSTANCE_COUNT)
        case kDebugConsoleLPUART:
            {
                /* Declare config sturcuture to initialize a uart instance. */
                lpuart_user_config_t lpuartConfig;
                lpuart_status_t status;

                /* Config the structure. */
                lpuartConfig.baudRate = baudRate;
                lpuartConfig.bitCountPerChar = kLpuart8BitsPerChar;
                lpuartConfig.parityMode = kLpuartParityDisabled;
                lpuartConfig.stopBitCount = kLpuartOneStopBit;

                /* Init LPUART device. */
                status =
                    LPUART_DRV_Init(uartInstance, &s_debugConsole.state.lpuartState, &lpuartConfig);
                if ((status != kStatus_UART_Success)&&(status != kStatus_UART_Initialized))
                {
                    s_debugConsole.type = kDebugConsoleNone;
                    return kStatus_DEBUGCONSOLE_Failed;
                }

                /* Set the funciton pointer for send and receive for this kind of device. */
                s_debugConsole.ops.Send = LPUART_DRV_SendPollBlocking;
                s_debugConsole.ops.Receive = LPUART_DRV_ReceivePollBlocking;

            }
            break;
#endif
#endif
        /* If new device is requried as the low level device for debug console,
         * Add the case branch and add the preprocessor macro to judge whether
         * this kind of device exist in this SOC. */
        default:
            /* Device identified is invalid, return invalid device error code. */
            return kStatus_DEBUGCONSOLE_InvalidDevice;
    }

    /* Configure the s_debugConsole structure only when the inti operation is successful. */
    s_debugConsole.instance = uartInstance;

#if ((defined(__GNUC__)) && (!defined(FSL_RTOS_MQX)))
    setvbuf(stdout, NULL, _IONBF, 0);
    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stderr, NULL, _IONBF, 0);
#endif

    return kStatus_DEBUGCONSOLE_Success;
}
Пример #8
0
static int nio_serial_init(void *init_data, void **dev_context)
{
    osa_status_t status;

    NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context;

    NIO_SERIAL_INIT_DATA_STRUCT *init = (NIO_SERIAL_INIT_DATA_STRUCT*)init_data;

    #if PLATFORM_LPUART_ENABLED

    assert(init->UART_INSTANCE < HW_LPUART_INSTANCE_COUNT);

    lpuart_user_config_t uartConfig =
    #else
    assert(init->UART_INSTANCE < HW_UART_INSTANCE_COUNT);

    uart_user_config_t uartConfig =
    #endif
    {
        .baudRate = init->BAUDRATE,
        .parityMode = init->PARITY_MODE,
        .stopBitCount = init->STOPBIT_COUNT,
        .bitCountPerChar = init->BITCOUNT_PERCHAR,
    };

    serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT*) OSA_MemAlloc(sizeof(NIO_SERIAL_DEV_CONTEXT_STRUCT));

    /* SDK HAL init */
    #if PLATFORM_LPUART_ENABLED
    if ( kStatus_UART_Success != LPUART_DRV_Init(init->UART_INSTANCE, &serial_dev_context->uart_state, &uartConfig))
    {
        errno = ENXIO;
    }

    /* LPUART handler interrupt installation */
    status = OSA_InstallIntHandler(g_lpuartRxTxIrqId[init->UART_INSTANCE], init->handler);
    if (kStatus_OSA_Success != status)
    {
      errno = ENXIO;
    }
    NVIC_SetPriority(g_lpuartRxTxIrqId[init->UART_INSTANCE], init->RXTX_PRIOR);
    NVIC_EnableIRQ(g_lpuartRxTxIrqId[init->UART_INSTANCE]);

    #else
    if ( kStatus_UART_Success != UART_DRV_Init(init->UART_INSTANCE, &serial_dev_context->uart_state, &uartConfig))
    {
        errno = ENXIO;
    }

    /* UART handler interrupt installation */
    status = OSA_InstallIntHandler(g_uartRxTxIrqId[init->UART_INSTANCE], init->handler);
    if (kStatus_OSA_Success != status)
    {
      errno = ENXIO;
    }
    NVIC_SetPriority(g_uartRxTxIrqId[init->UART_INSTANCE], init->RXTX_PRIOR);
    NVIC_EnableIRQ(g_uartRxTxIrqId[init->UART_INSTANCE]);
    #endif
    serial_dev_context->instance = init->UART_INSTANCE;
    *dev_context = (void*)serial_dev_context;
    return 0;
}

static int nio_serial_deinit(void *dev_context)
{
    NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context;
    #if PLATFORM_LPUART_ENABLED
    LPUART_DRV_Deinit(serial_dev_context->instance);
    #else
    UART_DRV_Deinit(serial_dev_context->instance);
    #endif
    OSA_MemFree(dev_context);
    return 0;
}
Пример #9
0
int main()
{

	char * AT = "\r\nAT\r\n";//Setting up a char variable AT for the a long string
	char * PIN_CHECK = "\r\nAT+CPIN?\r\n";//Setting up a char variable PIN_CHECK for the a long string
	char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";//Setting up a char variable ENTER_PIN for the a long string
	char * CREG = "\r\nAT+CREG?\r\n";//Setting up a char variable CREG for the a long string
	char response[20]; //A character buffer called response that can hold 20 characters
	int result = 0;	//int result to check the value of the response sent back
	int transmit_send = 0;
	volatile int CurrentTick;	//Volitile interger to hold the current tick count of the current time
	char * ptr;	//Character
	char * stat;
	enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED};
	enum STATES CurrentState = INIT;
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	buffer_init();
	hardware_init();
	//UART0_config();
	PIT_Configure_interrupt_mode(1);
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);
	//PRINTF("UART0 Test Code\n\r");
	//PRINTF("Any entered character will be echoed\r\n\n");
	while(1)
	{
		switch(CurrentState)
		{
		case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
			printf("Testing Modem Connection\n");
			result = send_command(AT, response, sizeof(response), 2000);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" was returned by MODEM
				CurrentState = CHECK_PIN;
			else	//incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		case CHECK_PIN:	//Check if SIM card is ready
			result = send_command(PIN_CHECK, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				if(strstr(response, "READY"))
				{
					CurrentState = CHECK_NETWORK_REG;
				}
				else if(strstr(response, "SIM PIN"))
				{
					CurrentState = SEND_PIN;
				}
			}
			else
				CurrentState = INIT;
			break;

		case SEND_PIN:	//Send PIN code. "OK" response if PIN is correct
			result = send_command(ENTER_PIN, response, sizeof(response),10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				CurrentState = CHECK_NETWORK_REG;
			}
			else
				CurrentState = INIT;
			break;


		case CHECK_NETWORK_REG:	//check if registered on mobile network
			result = send_command(CREG, response, sizeof(response), 20);
			if(strstr(response, "+CREG"))
			{
				stat = (char *)strstr(response,":");
				stat += 4;
				switch(*stat)
				{
				case '0':
					CurrentState = INIT;
					break;
				case '1':
					CurrentState = SEND_SMS;
					break;
				case '2':
					CurrentTick = tick_count;
					while((tick_count - CurrentTick) < 5)
					{}
					CurrentState = CHECK_NETWORK_REG;
					break;
				case '3':
					CurrentState = INIT;
					break;
				case '4':
					CurrentState = CONNECTED;
					break;
				case '5':
					CurrentState = SEND_SMS;
					break;

				}
			}


		case SEND_SMS:	//Send a text message
			transmit_send = send_sms("\"0877763894\"","\"Testing 123		\"");
			if(transmit_send == SUCCESS)
			{
				CurrentState = CONNECTED;
			}
			else if(transmit_send == FAIL)
			{
				printf("A transmission fail has been detected or you have timed out\r\n");
				CurrentState = SEND_SMS;
			}
			else if(transmit_send == ERROR)
			{
				printf("A transmission ERROR has been detected,rebooting\r\n");
				CurrentState = INIT;
			}
			break;

		case CONNECTED:
			printf("\nInside Connected \r\n");
			while(1)	//dummy loop
			{}
			break;

		default:
			break;
		}//end switch-case
	}
}
int main(void)
{
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	long int x;
	int recieve_size=0;
	char AT[] = "AT\r";
	char CMGF[] = "AT+CMGF=1\r";
	char CMGS[] = "AT+CMGS=\"+353877763894\"\r";
	char MESSAGE[] = "HELLO AONGHUS KL26Z \x1A";

	char response[200];
	enum STATES {INIT,TXT_MODE,SEND_SMS,SEND_MSG};
	enum STATES CurrentState = INIT;
	uint32_t byteCountBuff = 0;
    //Initialise the FRDM-KL26Z Board
	hardware_init();
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);
	PRINTF("Full test of send/recieve on UART1\r\n");
	int i = 0,y;
	for(y=0;y<=sizeof(response);y++)
		response[i]='c';

	byteCountBuff = sizeof(AT);
	wait_time = 16000u;
    while(1){
    	switch(CurrentState){
			case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size =4;
				byteCountBuff = sizeof(AT);
				result = send_command(1,AT,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned INIT\r\n");//"OK" was returned by MODEM
					CurrentState = TXT_MODE;
				}
				break;
			case TXT_MODE:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size =4;
				byteCountBuff = sizeof(CMGF);
				result = send_command(1,CMGF,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned TXT_MODE\r\n");//"OK" was returned by MODEM
					CurrentState = SEND_SMS;
				}
				break;
			case SEND_SMS:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size = 2;
				byteCountBuff = sizeof(CMGS);
				result = send_command(1,CMGS,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned SEND_SMS\r\n");//"OK" was returned by MODEM
					CurrentState = SEND_MSG;
				}
				break;
			case SEND_MSG:	//Check connection to MODEM by sending AT. Expected response is OK
				recieve_size =8;
				byteCountBuff = sizeof(MESSAGE);
				result = send_command(1,MESSAGE,byteCountBuff,wait_time,response,recieve_size);
				if(result == SUCCESS){
					printf("returned SEND_MSG\r\n");//"OK" was returned by MODEM
					//CurrentState = CHECK_PIN;
				}
				break;
			default:
				break;
		}//end switch-case
    }
    /* Never leave main */
    return 0;
}