I have used LCD port of this RX111 and its working but I am not able to powerup the usb port of RX111.
please kindly suggest me a solution...I have put the main code of it
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
Clear_Display();
DisplayCenter(0, (uint8_t *)"USB Project");
/* Start toggling the LEDs */
R_CMT1_Start();
/* Configure a switch press callback function */
SetSwitchPressCallback(cb_switch_press);
while (1)
{
if( R_usb_cstd_Scheduler() == USB_FLGSET )
{
R_usb_hstd_HcdTask(); /* HCD Task */
R_usb_hstd_MgrTask(); /* MGR Task */
usb_hmsc_Task(); /* HMSC Task */
usb_hmsc_StrgDriveTask(); /* HSTRG Task */
usb_hmsc_SampleAplTask(); /* HMSC Sample Task */
}
}
} /* eof main() */
Related
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM6_Init();
MX_UART7_Init();
MX_USART3_UART_Init();
MX_UART5_Init();
MX_USART1_UART_Init();
MX_USART6_UART_Init();
MX_UART8_Init();
MX_SPI2_Init();
MX_SPI3_Init();
MX_SPI5_Init();
MX_I2C1_Init();
MX_RNG_Init();
MX_TIM3_Init();
MX_USB_OTG_FS_PCD_Init();
MX_RTC_Init();
MX_FMC_Init();
MX_TIM7_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_DMA(&huart3,(uint8_t*)RX_BUFFER3,RX_BUFFER3_SIZE);
HAL_UART_Receive_DMA(&huart7,(uint8_t*)RX_BUFFER7,RX_BUFFER7_SIZE);
HAL_UART_Receive_DMA(&huart5,(uint8_t*)BW_BUFFER5, BW_BUFFER5_SIZE);
#if BW16_ENABLE
// BW16 RESET
bw16_Reset();
// BW16 Init
bw16_init(&huart5);
// BW16 Rx Buffer 더미 데이터가 있다면 제거하고 DMA 초기화
RxCntUart5 = __HAL_DMA_GET_COUNTER(huart5.hdmarx);
if(BW_BUFFER5_SIZE != RxCntUart5)
{
__HAL_DMA_DISABLE(huart5.hdmarx);
__HAL_DMA_SET_COUNTER(huart5.hdmarx, BW_BUFFER5_SIZE);
__HAL_DMA_ENABLE(huart5.hdmarx);
// memset하고 나서 데이터가 12개밖에 안 받아짐 근데 안하면 에러
// 20200907
//memset(RX_BUFFER5,0x00,sizeof(RX_BUFFER5));
}
#endif
/* USER CODE END 2 */
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
HAL_TIM_Base_Start_IT(&htim6);
HAL_TIM_Base_Start_IT(&htim7);
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 256);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* definition and creation of TcpTask */
osThreadDef(TcpTask, Tcp_Task, osPriorityIdle, 0, 256);
TcpTaskHandle = osThreadCreate(osThread(TcpTask), NULL);
/* definition and creation of Usart3Task */
osThreadDef(Usart3Task, Usart3_Task, osPriorityIdle, 0, 256);
Usart3TaskHandle = osThreadCreate(osThread(Usart3Task), NULL);
/* definition and creation of Uart7Task */
osThreadDef(Uart7Task, Uart7_Task, osPriorityIdle, 0, 256);
Uart7TaskHandle = osThreadCreate(osThread(Uart7Task), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
HAL_UART_Transmit(&huart3,"START! READY!\r\n",13,0xFFFFFFFF);
/* USER CODE END RTOS_THREADS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
I use stm32 If osKernelStart(); is executed in the above code, the repeat statement cannot be executed, so how can I get to the repeat statement?
This is the code to transfer the sensor value through Bluetooth communication, but I have to use another code in the while statement
As the osKernelStart() code is executed, the while statement must also be executed
Please tell me how to do it
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_TIM6_Init();
MX_UART7_Init();
MX_USART3_UART_Init();
MX_UART5_Init();
MX_USART1_UART_Init();
MX_USART6_UART_Init();
MX_UART8_Init();
MX_SPI2_Init();
MX_SPI3_Init();
MX_SPI5_Init();
MX_I2C1_Init();
MX_RNG_Init();
MX_TIM3_Init();
MX_USB_OTG_FS_PCD_Init();
MX_RTC_Init();
MX_FMC_Init();
MX_TIM7_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_DMA(&huart3, (uint8_t*)RX_BUFFER3, RX_BUFFER3_SIZE);
HAL_UART_Receive_DMA(&huart7, (uint8_t*)RX_BUFFER7, RX_BUFFER7_SIZE);
#if BW16_ENABLE
HAL_UART_Receive_DMA(&huart5, (uint8_t*)BW_BUFFER5, BW_BUFFER5_SIZE);
// BW16 RESET
bw16_Reset();
// BW16 Init
bw16_init(&huart5);
RxCntUart5 = __HAL_DMA_GET_COUNTER(huart5.hdmarx);
if(BW_BUFFER5_SIZE != RxCntUart5)
{
__HAL_DMA_DISABLE(huart5.hdmarx);
__HAL_DMA_SET_COUNTER(huart5.hdmarx, BW_BUFFER5_SIZE);
__HAL_DMA_ENABLE(huart5.hdmarx);
}
#endif
/* USER CODE END 2 */
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
HAL_TIM_Base_Start_IT(&htim6);
HAL_TIM_Base_Start_IT(&htim7);
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 256);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* definition and creation of TcpTask */
osThreadDef(TcpTask, Tcp_Task, osPriorityIdle, 0, 256);
TcpTaskHandle = osThreadCreate(osThread(TcpTask), NULL);
/* definition and creation of Usart3Task */
osThreadDef(Usart3Task, Usart3_Task, osPriorityIdle, 0, 256);
Usart3TaskHandle = osThreadCreate(osThread(Usart3Task), NULL);
/* definition and creation of Uart7Task */
osThreadDef(Uart7Task, Uart7_Task, osPriorityIdle, 0, 256);
Uart7TaskHandle = osThreadCreate(osThread(Uart7Task), NULL);
/* definition and creation of BWdataTask */
osThreadDef(BWdataTask, bwdata_Task, osPriorityIdle, 0, 256);
BWdataTaskHandle = osThreadCreate(osThread(BWdataTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
void bwdata_Task(void const * argument)
{
/* USER CODE BEGIN bwdata_Task */
/* Infinite loop */
for(;;)
{
SCB_InvalidateDCache_by_Addr ((uint32_t *)BW_BUFFER5, BW_BUFFER5_SIZE);
pos2 = __HAL_DMA_GET_COUNTER(huart5.hdmarx);
pos = BW_BUFFER5_SIZE - pos2;
if(pos != old_pos)
{
if(pos > old_pos)
{
memcpy(rx_temBuffer, &BW_BUFFER5[old_pos], pos - old_pos);
rx_size =+ pos - old_pos;
}
else
{
memcpy(rx_temBuffer, &BW_BUFFER5[old_pos], get_dma_total_size() - old_pos);
rx_size += get_dma_total_size() - old_pos;
if(pos > 0){
memcpy(&rx_temBuffer[get_dma_total_size() - old_pos], &BW_BUFFER5[0], pos);
rx_size += pos;
}
}
old_pos = pos;
if(rx_size > 0)
{
HAL_UART_Receive_DMA(&huart5, (uint8_t*)BW_BUFFER5, BW_BUFFER5_SIZE);
printf("%s\n\r", (char*)&BW_BUFFER5);
#if BW16_ENABLE
bw16_send_data (&huart5, rx_size, "1", rx_temBuffer);
#endif
}
rx_size = 0;
}
}
/* USER CODE END bwdata_Task */
}
I want to write the code above so that I can send and receive wifi, but the wifi connection is good.
However, if I send a message from the server to the client (stm32), it will be printed only once, and I receive a message after that, but it doesn't printf. It says there is a problem like below, how can I solve it?
An MPU or Execute Never (XN) default memory map access violation has occurred on an instruction fetch (CFSR.IACCVIOL, MMFAR).
It's a reaction that comes out if you send it only once below.
I am trying to read ADC values from an arduino shield connected to my board. The Arduino shield is an already tested custom board which sends data when a contact between a sensor and a finger is detected.
I developed a program using STM32Cube IDE to be able to read these values and display it periodically. This program is based on STemWin example. Unfortunately, after first read from the program, the value is not updated and the rest of the features are not working anymore. The program is stuck. If I comment the code which periodically reads data from ADC then the program works normally.
Here is the content of my main :
/* Configure the MPU attributes */
MPU_Config();
/* Invalidate I-Cache : ICIALLU register */
SCB_InvalidateICache();
/* Enable branch prediction */
SCB->CCR |= (1 << 18);
__DSB();
/* Invalidate I-Cache : ICIALLU register */
SCB_InvalidateICache();
/* Enable I-Cache */
SCB_EnableICache();
SCB_InvalidateDCache();
SCB_EnableDCache();
/* STM32F7xx HAL library initialization:
- Configure the Flash ART accelerator on ITCM interface
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock # 200 Mhz */
SystemClock_Config();
/* Init GPIO */
MX_GPIO_Init();
/* Init ADC3 */
MX_ADC3_Init();
/* Configure the board */
k_BspInit();
/* Initialize RTC */
k_CalendarBkupInit();
/* Create GUI task */
osThreadDef(GUI_Thread, GUIThread, osPriorityNormal, 0, 2 * 1024);
osThreadCreate(osThread(GUI_Thread), NULL);
/* Add Modules*/
k_ModuleInit();
/* Link modules */
k_ModuleAdd(&audio_player_board);
k_ModuleAdd(&redfrog_loader_board);
k_ModuleAdd(&redfrog_workstation_board);
#if !defined ( __GNUC__ )
k_ModuleAdd(&video_player_board);
#endif
/*k_ModuleAdd(&audio_recorder_board);
k_ModuleAdd(&vnc_server);
k_ModuleAdd(&gardening_control_board);
k_ModuleAdd(&home_alarm_board);
k_ModuleAdd(&games_board);
k_ModuleAdd(&settings_board);*/
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
for (;;)
;
Here is the content of MX_ADC3_Init and MX_GPIO_Init functions :
/**
* #brief ADC3 Initialization Function
* #param None
* #retval None
*/
static void MX_ADC3_Init(void) {
/* USER CODE BEGIN ADC3_Init 0 */
/* USER CODE END ADC3_Init 0 */
ADC_ChannelConfTypeDef sConfig = { 0 };
/* USER CODE BEGIN ADC3_Init 1 */
__HAL_RCC_ADC3_CLK_ENABLE()
;
/* USER CODE END ADC3_Init 1 */
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DMAContinuousRequests = ENABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc3) != HAL_OK) {
printf("NOK");
}
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) {
printf("NOK");
}
/* USER CODE BEGIN ADC3_Init 2 */
/* USER CODE END ADC3_Init 2 */
}
static void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct = { 0 };
__HAL_RCC_GPIOA_CLK_ENABLE()
;
/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
}
And finally here is the GUIThread function which is called as a thread in main function.
/**
* #brief Start task
* #param argument: pointer that is passed to the thread function as start argument.
* #retval None
*/
static void GUIThread(void const *argument) {
/* Initialize Storage Units */
k_StorageInit();
/* Initialize GUI */
GUI_Init();
WM_MULTIBUF_Enable(1);
GUI_SetLayerVisEx(1, 0);
GUI_SelectLayer(0);
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
/* Set General Graphical proprieties */
k_SetGuiProfile();
/* Demo Startup */
k_StartUp();
/* Create Touch screen Timer */
osTimerDef(TS_Timer, TimerCallback);
lcd_timer = osTimerCreate(osTimer(TS_Timer), osTimerPeriodic, (void*) 0);
/* Start the TS Timer */
osTimerStart(lcd_timer, 100);
/* Show the main menu */
k_InitMenu();
WM_HWIN hItem = TEXT_CreateEx(350, 100, 80, 15, WM_GetDesktopWindowEx(0),
WM_CF_SHOW, 0, 33, "0");
TEXT_SetFont(hItem, GUI_FONT_13B_ASCII);
TEXT_SetTextColor(hItem, GUI_BLACK);
HAL_ADC_Start(&hadc3);
HAL_StatusTypeDef res;
/* Gui background Task */
while (1) {
uint32_t InitTick = 0;
GUI_Exec(); /* Do the background work ... Update windows etc.) */
res = HAL_ADC_PollForConversion(&hadc3,
HAL_MAX_DELAY);
switch (res) {
case HAL_OK:
if ((WM_IsVisible(hItem))
&& ((osKernelSysTick() - InitTick) > 500)) {
g_ADCValue = HAL_ADC_GetValue(&hadc3);
g_MeasurementNumber++;
hItem = WM_GetDialogItem(WM_GetDesktopWindowEx(0), 33);
char str[12];
sprintf((char*) str, "%lu", g_ADCValue);
TEXT_SetText(hItem, str);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
}
break;
case HAL_ERROR:
printf("ERROR");
break;
case HAL_BUSY:
printf("BUSY");
break;
case HAL_TIMEOUT:
printf("TIMEOUT");
break;
}
osDelay(20); /* Nothing left to do for the moment ... Idle processing */
}
}
The while loop at the end contains the code that should allow me to read values periodically from GPIOPin0/ADC3Channel0. It works a first time since when I reset the board the value is changing. But then the program is stuck.
I need your help to understand what I am doing wrong.
Thank you very much.
The ADC only converts one sample.
This is caused by your call of res = HAL_ADC_PollForConversion(&hadc3, HAL_MAX_DELAY);
This function will stop the ADC after the conversion is finished, so next time you come to this call your program get blocked since the EOC flag is never set.
Simply add a HAL_ADC_Start(&hadc3); within your while(1) loop and you will always get new values.
Later you could change your code to use DMA and the ADC could run without waiting :)
I'm beginer in STM32, i have a project and need to receive data from another device like arduino, and now I try transmit data from UART 3 and I receive data with UART 1. but I can't get any data. I connect TX uart 3 to RX uart 1 and TX uart 1 to RX uart 3.
/* USER CODE BEGIN PV */
int i = 0;
char bufferReceive[6], bufferTransmit[10];
/* USER CODE END PV */
/* USER CODE BEGIN 0 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART1) //current UART
{
HAL_UART_Receive_IT(&huart1, (uint8_t*)bufferReceive, 1); //activate UART receive interrupt every time
}
}
/* USER CODE END 0 */
int main(void)
{
HAL_UART_Receive_IT(&huart1, (uint8_t*)bufferReceive, 1);
while (1)
{
/* USER CODE END WHILE */`enter code here`
sprintf(bufferTransmit,"%d\n",i);
HAL_UART_Transmit(&huart3, (uint8_t*)bufferTransmit, sizeof(bufferTransmit), 1000);
HAL_Delay(500);
i++;
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
First thing your code is messy and hard to read.
Second, you are missing your entire initialization region before while(1) so your system shouldn't be doing anything.
/* USER CODE BEGIN PV */
int i = 0;
char bufferReceive[6], bufferTransmit[10];
/* USER CODE END PV */
/* USER CODE BEGIN 0 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART1)
{
HAL_UART_Receive_IT(&huart1, (uint8_t*)bufferReceive, 1);
}
}
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART3_UART_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart1, (uint8_t*)bufferReceive, 1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
sprintf(bufferTransmit,"%d\n",i);
HAL_UART_Transmit(&huart3, (uint8_t*)bufferTransmit, sizeof(bufferTransmit), 1000);
HAL_Delay(500);
i++;
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
You are receiving one byte at HAL_UART_Receive_IT(&huart1, (uint8_t*)bufferReceive, 1);.
Which does not wait it simply moves onward.
Next, you transmit bufferTransmit which then causes UART1 to receive one byte and continues to receive all bytes one by one in the same memory location.
It seems you are not using i properly as you probably want something like HAL_UART_Receive_IT(&huart1, (uint8_t*)&bufferReceive[i], 1);
You do not initialize anything. Peripherals, pins, clocks etc have to be set up before they can work.
I am working with GSM (sim900a) Module interfaced with PIC18F4520 Microcontroller.
Here I am trying to send SMS through PIC controller serially to GSM Module but unable to receive any response from GSM and not receiving any Messages.
When I am trying to connect only GSM Module to Hyperterminal then I am able to send SMS. In the similar fashion when I am trying to send AT commands from PIC to HYPERTERMINAL then I am receiving Commands Serially.
Code Below
#include<p18f4520.h> /* Header File */
#include<string.h>
void delay_ms(int ms);
void Data(char Value);
void Cmd(char Value);
char temp;
void main()
{
char tocheck[] ="AT";/*Basic command to test GSM is working or not */
char sendingsmsmode[]="AT+CMGF=1";/* To change the GSM Module in SMS
sending Mode */
char newsms[]="AT+CMGS=918500923915";/*Set Text mode for SMS */
char msg[]="WelcometoGSM";/* The text which you want to send */
char terminator=0x1A;
int i=0;
TRISC = 0x80; /* RC6=0 (O/P) RC7=1(I/P) */
SPBRG = 0x33; /* Serial Port Baud rate Generator (9600) */
TXSTA = 0X24; /* Transmission Enabling(TXEN=1,SYNC=0,BRGH=1)
*/
RCSTA = 0X90; /* Rception Enabling (SPEN=1,CREN=1) */
TRISC=0X00; /* (RC1,RC0 ->O/P Setting by Zero)
*/
TRISD=0X00; /* PORTD (0 - 7)pins Config as Output
*/
while(tocheck[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=tocheck[i];
delay_ms(30);
i++;
}
i=0;
while(sendingsmsmode[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=sendingsmsmode[i];
delay_ms(30);
i++;
}
i=0;
while(newsms[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=newsms[i];
delay_ms(30);
i++;
}
i=0;
while(msg[i]!='\0'){
while(TXSTAbits.TRMT==0);
TXREG=msg[i];
delay_ms(30);
i++;
}
TXREG=terminator;
delay_ms(3000);
while(1);
}
void Cmd(char Value)
{
PORTD=Value;
PORTCbits.RC1=0; /* RC1=0(RS=0) [Command Registr
Selection]) */
PORTCbits.RC0=0; /* RC0=0(R/W=0) [Write Process])
*/
PORTCbits.RC2=1; /* RC2=1(Enable=1) [Enable Line ON]
*/
delay_ms(4); /* Minimun Delay For Hold On Data
*/
PORTCbits.RC2=0; /* RC2=0(Enable=0) [Enable Line OFF]
*/
}
void Data(char Value)
{
PORTD=Value;
PORTCbits.RC1=1; /* RC1=1(RS=1) [Data Registr
Selection]) */
PORTCbits.RC0=0; /* RC0=0(R/W=0) [Write Process])
*/
PORTCbits.RC2=1; /* RC2=1(Enable=1) [Enable Line ON]
*/
delay_ms(4); /* Minimun Delay For Hold On Data
*/
PORTCbits.RC2=0; /* RC2=0(Enable=0) [Enable Line OFF]
*/
}
void delay_ms(int ms)
{
int i,count;
for(i=1;i<=ms;i++)
{
count=498;
while(count!=1)
{
count--;
}
}
}
You need to send CR or CR+LF (characters number 13 and 10 respectively) after every string you send to the modem.
When using a terminal emulator like HyperTerminal, you press the Enter key, right? If you don't press that key, the modem does not know that the command is terminated and must be executed. The same must be done in your firmware.
There is more: you must allow some delay, and you should read back modem responses, but this could be a second step; first of all, to check the setup is working at the base level, you must send an "AT", followed by a CR, then see if the modem replies with OK (+ CR and LF...).
Modify
char tocheck[] ="AT";
in
char tocheck[] ="AT\r"; // the \r is the CR (carriage return)
and you will see that the modem will reply, if all is connected well.