Hi, and thanks a lot for your answer.
I am using a function made by the provider.
Code:
unsigned char USART_WriteBuffer(
AT91S_USART *usart,
void *buffer,
unsigned int size)
{
// Check if the first PDC bank is free
if ((usart->US_TCR == 0) && (usart->US_TNCR == 0)) {
usart->US_TPR = (unsigned int) buffer;
usart->US_TCR = size;
usart->US_PTCR = AT91C_PDC_TXTEN;
return 1;
}
// Check if the second PDC bank is free
else if (usart->US_TNCR == 0) {
usart->US_TNPR = (unsigned int) buffer;
usart->US_TNCR = size;
return 1;
}
else {
return 0;
}
}
I am writing in this buffer in my main just to test:
USART_WriteBuffer( pUSART0, "ATI", 3);
Normally, I would obtain the reference ID of my GSM module.
For the reception, I have based the code on the one for the GPS module.
Code:
void Usart0IrqHandler (void)
{
volatile AT91PS_USART pUsart0 = AT91C_BASE_US0; // create a pointer to USART0 structure
// determine which interrupt has occurred
// assume half-duplex operation here, only one interrupt type at a time
if ((pUsart0->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY)
{
char ch;
// we have a receive interrupt,
// remove it from Receiver Holding Register and place into buffer[]
ch = pUsart0->US_RHR;
if (ch == 'A') // Resync line
nChars = 0;
Buffer[nChars++] = ch; // Store char and advance
if (nChars >= sizeof(Buffer)) // Enough to hold the biggest NMEA sentence, YMMV
nChars = 0; // Wrap
if (ch == 0x0D) // CR, we ignore LF
{
Buffer[nChars - 1] = 0; // Place a NUL so C string functions actually work
// Should check for the right AT sentence here, and perhaps parse it properly
if ( (Buffer[0] == 'A') && (Buffer[1] == 'T'))
{
for(int i = 0 ; i <= 100 ; i++){
gsm_data[i]= Buffer[i];
}
flag_gsm = 1;
}
nChars = 0; // reset
}
}
}
The problem is that I cannot find the end of transmit character for the received data.
Otherwise, when I am debugging (I have commented most of the handler code, I just keep the " Buffer[nChars++] = ch;" and the condition to enter in the loop ) my buffer of reception conatins "ATI" and not the identification number...
I have tried with AT+ATI, AT+ATI;. I do not really understand the syntax written in the AT commands pdf. I have also had a look on
http://olimex.wordpress.com/tag/gsm/and apparently it is quite easy, but unfortunately, I always receive the data I have sent.