I am planning to use FCM, instead of Open UART, to access UART because I am only going to send and receive raw data.
Basically, I am trying to communicate to a meter.
I am just cautious to experiment in our modem because it might be locked and I don’t have a dev kit to restore it.
If you don’t mind, I would like to ask for some basic examples or some assistance on how to communicate to a meter using FCM to access UART.
The secret is to provide a delay at the start of your application before it “seizes” the UART: this will give you time to kill the application - with AT+WOPEN=0 - before it locks you out.
Is there any reason that you want to use FCM rather than OpenUART? FCM is somewhat convoluted to get started with, and OpenUART is closer to ‘normal’ uart programming than FCM is.
Note that you have to ‘assign’ the uart to OpenAT using the AT+WMFM command if you are using OpenUART. This will stop you using the uart for normal at commands and development, so I would be making sure that you can connect to the modem either using usb or another uart … use a gpio to signal to your OpenAT app to disconnect from the uart.
Oh, and there are some worked examples you can use to create new projects in Developer Studio. When creating a new project, step through each step using the next key and you’ll get to a page that lets you select a sample project to base your new project on.
So far, this is what I have done. I only pasted the necessary codes for my questions.
bool EvhCrtlUart1(adl_fcmEvent_e event) {
ascii *test;
switch (event) {
case ADL_FCM_EVENT_FLOW_OPENNED:
// Switch to data mode
adl_fcmSwitchV24State(handle_uart1,ADL_FCM_V24_STATE_DATA);
break;
case ADL_FCM_EVENT_V24_DATA_MODE:
// sending data to the external application via V24 serial link
test = "Test data to be sent to external device.";
adl_fcmSendData(handle_uart1, (u8 *)test, 50);
// Question 1: Is this the right place where I should send data
// from the modem to the external device through UART?
// Switch to AT mode
adl_fcmSwitchV24State(handle_uart1,ADL_FCM_V24_STATE_AT);
break;
case ADL_FCM_EVENT_V24_AT_MODE:
break;
case ADL_FCM_EVENT_RESUME:
break;
case ADL_FCM_EVENT_MEM_RELEASE:
break;
default:
return FALSE;
break;
}
return TRUE;
}
bool EvhDataUart1(u16 datalength, u8 *data){
{
// Question 2: Based on OpenAT docs, the manipulation of the data is done here.
// What data is this? Is this from the modem which is sent to external device or
// the data from external device going back to the modem?
adl_fcmSendData(handle_uart1, data, datalength);
return TRUE;
}
void main_task ( void )
{
// (Just some initialization. I just didn't include the code.)
initUART1(DATAMODE, 9600 , DATA8_STOP1 , NONE_PARITY , NO_CTS_RTS);
}
Question 3: Where or what function/method is needed in order to get the data that is returned back from the external device to the modem?
I am still new to this world, so hopefully, you will be patient.
the parameter, *data, contains the data from my external device, which in my case is a meter?
If so, all the information in the *data parameter comes from the meter?
I am just a bit confused on how the Data Handler and the Control Handler function separately.
In my Control Handler, I have this code:
case ADL_FCM_EVENT_V24_DATA_MODE:
len = sizeof(myArray);
adl_fcmSendData(handle, myArray, len);
As far as I know, this will only send data to my external device (meter). But when I spy the port using a serial port monitor, this code prints the data sent to the external device and the data received from the external device. So the output contains both the sent and the received. Should the received data only be in the Data Handler?
I also have this code in my Data Handler but it seems it is not outputting something:
bool fcmDataH(u16 dataLen, u8 *data){
ascii buf[256];
/* check for ESC to switch to AT MODE */
if(data[0] == 27) {
adl_fcmSwitchV24State(handle,ADL_FCM_V24_STATE_AT);
}
wm_sprintf(buf, "Data: %s; Len: %d\r\n", data, dataLen);
adl_atSendResponse(ADL_AT_RSP, buf);
return TRUE;
}
So currently, I am still trying to figure out when and how the Data Handler is called.
I might be missing something.