This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Tivaware EEPROM Read&Write | Example Code

Other Parts Discussed in Thread: TM4C123GH6PM

// www.teknikyazi.com

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/eeprom.h"
#include "utils/uartstdio.h"
 
 
#define E2PROM_TEST_ADRES 0x0000 
 
struct E2PROM
{
	uint8_t value1;
	uint8_t value2;
	uint16_t value3;
	uint8_t value4[12];
}; 
 
 
 
struct E2PROM e2prom_write_value = {5,7,9826, "Hello World"}; /* Write struct */
struct E2PROM e2prom_read_value =  {0,0,0,""}; /* Read struct */
 
 
int main(void) 
{
	uint32_t e2size,e2block;
 
	SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // islemcimizi 80 Mhz'e ayarlıyoruz.
 
	/* UART SETTINGS */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTStdioConfig(GPIO_PORTA_BASE,115200,SysCtlClockGet());
	/*******************************/
 
	/* EEPROM SETTINGS */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); // EEPROM activate
	EEPROMInit(); // EEPROM start
	/*******************************/
 
	UARTprintf("EEPROM Test Program ,, Teknikyazi.com\r\n");
 
 
	e2size = EEPROMSizeGet(); // Get EEPROM Size 
	UARTprintf("EEPROM Size %d bytes\n", e2size);
 
	e2block = EEPROMBlockCountGet(); // Get EEPROM Block Count
	UARTprintf("EEPROM Blok Count: %d\n", e2block);
 
	UARTprintf("Write Try > Address %u: Struct : {%u,%u,%u,%s}\n", E2PROM_TEST_ADRES, e2prom_write_value.value1, e2prom_write_value.value2, e2prom_write_value.value3, e2prom_write_value.value4);
	EEPROMProgram((uint32_t *)&e2prom_write_value, E2PROM_TEST_ADRES, sizeof(e2prom_write_value)); //Write struct to EEPROM start from 0x0000
 
	EEPROMRead((uint32_t *)&e2prom_read_value, E2PROM_TEST_ADRES, sizeof(e2prom_read_value)); //Read from struct at EEPROM start from 0x0000
	UARTprintf("Read Try > Address %u: Struct : {%u,%u,%u,%s}\n", E2PROM_TEST_ADRES, e2prom_read_value.value1, e2prom_read_value.value2, e2prom_read_value.value3, e2prom_read_value.value4);
 
while(1)
 {
 }
 
}

  • Hello Metin,

    So what is the issue? Based on the code post

    1. Please check if EEPROMInit returns OK code

    2. In the write data, I am not sure if a string would be written as a string and then retrieved in the same manner. You would have to break the characters as store them accordingly in EEPROM.

    Regards

    Amit

  • I don't have any issue.. I searched this example but i didn't find , then i did. Now i am sharing for anyone. 

  • Hi,

    Good for you - but what Amit suggest is to make a dump of your EEPROM and check how many bytes are spent with your program. Compare with E2PROM struct size.

    Petrei

  • Amit or Petrei , Can you improve it ? Change my code with good code :)

  • // www.teknikyazi.com
    
    
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_ints.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/eeprom.h"
    #include "utils/uartstdio.h"
     
     
    #define E2PROM_TEST_ADRES 0x0000 
     
    struct E2PROM
    {
    	uint8_t value1;
    	uint8_t value2;
    	uint16_t value3;
    	uint8_t value4[12];
    }; 
     
     
     
    struct E2PROM e2prom_write_value = {5,7,9826, "Hello World"}; /* Write struct */
    struct E2PROM e2prom_read_value =  {0,0,0,""}; /* Read struct */
     
     
    int main(void) 
    {
    	uint32_t e2size,e2block,returnCode;
     
    	SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // islemcimizi 80 Mhz'e ayarlıyoruz.
     
    	/* UART SETTINGS */
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    	GPIOPinConfigure(GPIO_PA0_U0RX);
    	GPIOPinConfigure(GPIO_PA1_U0TX);
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    	UARTStdioConfig(GPIO_PORTA_BASE,115200,SysCtlClockGet());
    	/*******************************/
     
    	/* EEPROM SETTINGS */
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); // EEPROM activate
    	
    	do
    	{
    		returnCode=EEPROMInit(); // EEPROM start
    	}
    	while(returnCode!=EEPROM_INIT_OK)
    	
    	
    	/*******************************/
     
    	UARTprintf("EEPROM Test Program ,, Teknikyazi.com\r\n");
     
     
    	e2size = EEPROMSizeGet(); // Get EEPROM Size 
    	UARTprintf("EEPROM Size %d bytes\n", e2size);
     
    	e2block = EEPROMBlockCountGet(); // Get EEPROM Block Count
    	UARTprintf("EEPROM Blok Count: %d\n", e2block);
     
    	UARTprintf("Write Try > Address %u: Struct : {%u,%u,%u,%s}\n", E2PROM_TEST_ADRES, e2prom_write_value.value1, e2prom_write_value.value2, e2prom_write_value.value3, e2prom_write_value.value4);
    	EEPROMProgram((uint32_t *)&e2prom_write_value, E2PROM_TEST_ADRES, sizeof(e2prom_write_value)); //Write struct to EEPROM start from 0x0000
     
    	EEPROMRead((uint32_t *)&e2prom_read_value, E2PROM_TEST_ADRES, sizeof(e2prom_read_value)); //Read from struct at EEPROM start from 0x0000
    	UARTprintf("Read Try > Address %u: Struct : {%u,%u,%u,%s}\n", E2PROM_TEST_ADRES, e2prom_read_value.value1, e2prom_read_value.value2, e2prom_read_value.value3, e2prom_read_value.value4);
     
    while(1)
     {
     }
     
    }
    

  • Hello Metin,

    There is nothing wrong with code as such, (except for doing return checks) if it works for your requirement. What is a good code is based on the context of the application!!!

    The EEPROM has word access only. If you can modify the code such that it can concatenate/join 8 and 16-bit words as a single 32-bit word and then it would be a good code example to optimize the usage of EEPROM words.

    Similarly, the EEPROM has a endurance of 500K Program/Erase cycles. If through Software you can make the endurance last longer, that would be an extremely useful code (This is amongst my to-do list)

    Regards

    Amit

  • Hi dear sirs,

    I guess that has something wrong in this code,

    Please check the start address of EEPROM, according to datasheet "0x400AF000"

    Best regards

    Tales Amorim

  • Hello Tales,

    Can you please refer to which line in the code post is wrong?

    Regards

    Amit

  • Hi Amit,

    I am trying to write some data into EEPROM memory as shown in the code below,
    #include "inc/tm4c123gh6pm.h" #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/sysctl.h" #include "driverlib/pin_map.h" #include "driverlib/debug.h" #include "driverlib/gpio.h" #include "driverlib/eeprom.h" uint32_t addr; uint32_t pui32Data[5]={0x01,0x02,0x03,0x04,0x05}; uint32_t pui32Data1[5]={0x06,0x07,0x08,0x09,0x10}; uint32_t pui32Data2[5]={0x11,0x12,0x13,0x14,0x15}; uint32_t pui32Read[5],pui32Read1[5],pui32Read2[15]; int main(void) { SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); EEPROMInit(); //EEPROMMassErase(); addr = 0x400af000; EEPROMProgram(pui32Data, addr, sizeof(pui32Data)); addr = 0x400af000; EEPROMRead(pui32Read, addr, sizeof(pui32Read)); addr = 0x400af040; EEPROMProgram(pui32Data1, addr, sizeof(pui32Data1)); addr = 0x400af040; EEPROMRead(pui32Read1, addr, sizeof(pui32Read1)); addr = 0x400af080; EEPROMProgram(pui32Data2, addr, sizeof(pui32Data2)); addr = 0x400af080; EEPROMRead(pui32Read2, addr, sizeof(pui32Read2)); } Here i am getting correct output, but if i first write the data continuously or one by one, after that if i am trying to read continuously or one by one then i am getting the same data (11,12,13,14,15) in all 3 reads. When i try to first write the data at random addresses, then if i try to read, at 2 addresses i get the same data.
    My requirement is, i should be able to write some no. of bytes at random addresses continuously, and then i should be able to read correct data. Is that possible? if not can you please help me out where i am doing mistake.

    Regards,
    Mamatha M
  • Hello Mamatha,

    The usage of the parameter addr is wrong. When the code has to access the eeprom it has use the absolute address for EEPROM word like 0x0, 0x4.... and not 0x400AF0XX

    Regards

    Amit

  • You are correct. Now it is working, thanks a lot.

    Regards,

    Mamatha M

  • Hi Amit,

    I have modified USB example code according to my requirements, have taken some data from the stellaris bulk USB device example application and writing that data into EEPROM. If i am trying to write the address(first 3 characters), size(next 2 characters), and  data(no of characters based on the size) as shown below, only it is writing first data (01,02,03) and the data with address starting from ff0 .. it is not writing 2nd and 3rd time data what i am passing..

    I have attached the part of modified code, hope you can understand. As you told i am using only offset address for eeprom write. Please tell me where i am doing mistake.  

    Ex: 040 is the addr, 03 is no. of bytes and rest are data.

    Regards,

    Mamatha M

  • Here have attached the code..

    Regards,

    Mamatha

    6253.EEPROM.txt
    static uint32_t
    EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data,
                      uint32_t ui32NumBytes)
    {
    
        uint32_t ui32Loop, ui32Space, ui32Count;
        uint32_t ui32ReadIndex;
        uint32_t ui32WriteIndex;
        tUSBRingBufObject sTxRing;
    		unsigned char Data_Merge_flag=0,Data_count=0,Addr_shift_Cnt=8,Rx_Arr_Index=0,EEPROM_Buff_Index=0,Addr_Flag=0,Error_Data_Index=0;
    		uint32_t	pui32eprom = 0x00, addrdata=0x00;
    		uint32_t pui32Weprom[64]={0x00};
    
        USBBufferInfoGet(&g_sTxBuffer, &sTxRing);
    
        ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer);
    
        ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes;
        ui32Count = ui32Loop;
    
        g_ui32RxCount += ui32NumBytes;
    
        ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer);
        ui32WriteIndex = sTxRing.ui32WriteIndex;
    	
    			for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    			{
    				pui32Data[Rx_Arr_Index]	=	g_pui8USBRxBuffer[ui32ReadIndex];
    			
    				ui32ReadIndex++;
    				ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ?
                            0 : ui32ReadIndex;			
    			}
    					
    			for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    			{
    				
    				if(Rx_Arr_Index<0x03)
    				{
    					addrdata = addrdata | (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << Addr_shift_Cnt);
    					Addr_shift_Cnt = Addr_shift_Cnt - 4;
    					if(Rx_Arr_Index == 0x02)
    					{
    							if((addrdata < 0x000) || (addrdata > 0xfff))
    							{
    									goto error;
    							}
    						if((addrdata >= 0x000) && (addrdata <= 0x0f0))
    							Addr_Flag = 1;
    					}
    				}
    			  if(Rx_Arr_Index==0x04)
    			  {
    					Data_count = (Ascii_To_Num(pui32Data[Rx_Arr_Index-1]) << 4) | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    					if(Addr_Flag == 1)
    					{
    					Data_count = (Data_count * 0x02)+0x04;
    					}
    					else
    					{
    						Data_count = Data_count +0x04;
    					}
    			  }
    								
    				if((Rx_Arr_Index>=0x05)&&(Rx_Arr_Index<=Data_count))
    				{
    					if( Addr_Flag == 1)
    					{
    						if(Data_Merge_flag == 0)
    						{
    							pui32eprom = (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << 4);
    							Data_Merge_flag=1;
    						}
    						else 
    						{
    							pui32eprom = pui32eprom | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    							if(pui32eprom > 0x59)
    							{
    								error:
    								for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++)
    								{
    									g_pui8USBTxBuffer[ui32WriteIndex] = Error_data[Error_Data_Index];
    								}
    								goto end;
    							}
    							pui32Data[Rx_Arr_Index] = pui32eprom;
    							Data_Merge_flag=0;
    							goto write;
    						}	
    					}
    					
    			 if((Rx_Arr_Index>Data_count) || (Addr_Flag == 0))
    				{
    					write:
    					pui32Weprom[EEPROM_Buff_Index++]=pui32Data[Rx_Arr_Index];
    					pui32eprom = 0x00;
    				}
    			if((Rx_Arr_Index>Data_count) && (Addr_Flag == 0))
    			break;
    			}	
    		}
    							EEPROMProgram(pui32Weprom, addrdata, sizeof(pui32Weprom));
    					
    		end:
        USBBufferDataWritten(&g_sTxBuffer, ui32Count);
        return(ui32Count);
      
    }
    int Ascii_To_Num(int Rx_Data)
    {
    					if((Rx_Data >= 0x30) && (Rx_Data <= 0x39))
    					{
    						Rx_Data = Rx_Data - 0x30;
    					}
    					else if((Rx_Data >= 0x61) && (Rx_Data <= 0x66 )) 
    					{
    						switch(Rx_Data)
    						{
    							case 0x61 :
    											Rx_Data = 0x0A;
    											break;
    							case 0x62 :
    											Rx_Data = 0x0B;
    											break;
    							case 0x63 :
    											Rx_Data = 0x0C;
    											break;
    							case 0x64 :
    											Rx_Data = 0x0D;
    											break;
    							case 0x65 :
    											Rx_Data = 0x0E;
    											break;
    							case 0x66 :
    											Rx_Data = 0x0F;
    											break;
    						}
    					}
      return Rx_Data;
    }
    
    main and rest all are almost same...

  • Hello Mamatha,

    I may need both PC side program and TM4C side CCS project to be able to help better.

    Meantime I will try to go through the code patch and see if I can figure it out.

    Regards

    Amit

  • I have attached .c file ..

    Regards,

    Mamatha M

  • 1641.usb code.txt
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/timer.h"
    #include "driverlib/rom.h"
    #include "usblib/usblib.h"
    #include "usblib/usb-ids.h"
    #include "usblib/device/usbdevice.h"
    #include "usblib/device/usbdbulk.h"
    #include "utils/ustdlib.h"
    #include "usb_bulk_structs.h"
    #include "driverlib/eeprom.h"
    #include "ADC_TM4C123G.h"
    #include "ADC_TM4C123.h"
    
    //*****************************************************************************
    // The system tick rate expressed both as ticks per second and a millisecond
    // period.
    //*****************************************************************************
    #define SYSTICKS_PER_SECOND     100
    #define SYSTICK_PERIOD_MS       (1000 / SYSTICKS_PER_SECOND)
    
    //*****************************************************************************
    // The global system tick counter.
    //*****************************************************************************
    volatile uint32_t g_ui32SysTickCount = 0;
    
    //*****************************************************************************
    // Variables tracking transmit and receive counts.
    //*****************************************************************************
    volatile uint32_t g_ui32TxCount = 0;
    volatile uint32_t g_ui32RxCount = 0;
    
    //*****************************************************************************
    //
    // Flags used to pass commands from interrupt context to the main loop.
    //
    //*****************************************************************************
    #define COMMAND_PACKET_RECEIVED 0x00000001
    #define COMMAND_STATUS_UPDATE   0x00000002
    
    volatile uint32_t g_ui32Flags = 0;
    uint32_t pui32Data[256];
    unsigned char Error_data[5]={0x77,0x72,0x6F,0x6E,0x67};//"wrong data";
    
    //*****************************************************************************
    // Global flag indicating that a USB configuration has been set.
    //*****************************************************************************
    static volatile bool g_bUSBConfigured = false;
    
    //*****************************************************************************
    // Interrupt handler for the system tick counter.
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        g_ui32SysTickCount++;
    }
    /***********************************************************************************************************
     * Function Name 			   :	Ascii_To_Num
     * Description of the function : This function is used to hex values into actual numbers.
     * Passed parameter			   :	Rx_Data
     * Return value				     :  Rx_Data
     ***********************************************************************************************************/
    int Ascii_To_Num(int Rx_Data)
    {
    					if((Rx_Data >= 0x30) && (Rx_Data <= 0x39))
    					{
    						Rx_Data = Rx_Data - 0x30;
    					}
    					else if((Rx_Data >= 0x61) && (Rx_Data <= 0x66 )) 
    					{
    						switch(Rx_Data)
    						{
    							case 0x61 :
    											Rx_Data = 0x0A;
    											break;
    							case 0x62 :
    											Rx_Data = 0x0B;
    											break;
    							case 0x63 :
    											Rx_Data = 0x0C;
    											break;
    							case 0x64 :
    											Rx_Data = 0x0D;
    											break;
    							case 0x65 :
    											Rx_Data = 0x0E;
    											break;
    							case 0x66 :
    											Rx_Data = 0x0F;
    											break;
    						}
    					}
      return Rx_Data;
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	EchoNewDataToHost
     * Description of the function : Receive new data and echo it back to the host.
     * Passed parameter			   :	tUSBDBulkDevice *psDevice : instance data for the device whose data is to be processed.
    															uint8_t *pui8Data : points to the newly received data in the USB receive buffer.
    															uint32_t ui32NumBytes : is the number of bytes of data available to be processed.
     * Return value				     :  static uint32_t ui32Count : is the number of bytes of data processed.
     ***********************************************************************************************************/
    
    static uint32_t
    EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data,
                      uint32_t ui32NumBytes)
    {
    
        uint32_t ui32Loop, ui32Space, ui32Count;
        uint32_t ui32ReadIndex;
        uint32_t ui32WriteIndex;
        tUSBRingBufObject sTxRing;
    		unsigned char Data_Merge_flag=0,Data_count=0,Addr_shift_Cnt=8,Rx_Arr_Index=0,EEPROM_Buff_Index=0,Addr_Flag=0,Error_Data_Index=0;
    		uint32_t	pui32eprom = 0x00, addrdata=0x00;
    		uint32_t pui32Weprom[64]={0x00};
    
        USBBufferInfoGet(&g_sTxBuffer, &sTxRing);
    
        ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer);
    
        ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes;
        ui32Count = ui32Loop;
    
        g_ui32RxCount += ui32NumBytes;
    
        ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer);
        ui32WriteIndex = sTxRing.ui32WriteIndex;
    	
    			for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    			{
    				pui32Data[Rx_Arr_Index]	=	g_pui8USBRxBuffer[ui32ReadIndex];
    			
    				ui32ReadIndex++;
    				ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ?
                            0 : ui32ReadIndex;			
    			}
    					
    			for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    			{
    				
    				if(Rx_Arr_Index<0x03)
    				{
    					addrdata = addrdata | (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << Addr_shift_Cnt);
    					Addr_shift_Cnt = Addr_shift_Cnt - 4;
    					if(Rx_Arr_Index == 0x02)
    					{
    							if((addrdata < 0x000) || (addrdata > 0xfff))
    							{
    									goto error;
    							}
    						if((addrdata >= 0x000) && (addrdata <= 0x0f0))
    							Addr_Flag = 1;
    					}
    				}
    			  if(Rx_Arr_Index==0x04)
    			  {
    					Data_count = (Ascii_To_Num(pui32Data[Rx_Arr_Index-1]) << 4) | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    					if(Addr_Flag == 1)
    					{
    					Data_count = (Data_count * 0x02)+0x04;
    					}
    					else
    					{
    						Data_count = Data_count +0x04;
    					}
    			  }
    								
    				if((Rx_Arr_Index>=0x05)&&(Rx_Arr_Index<=Data_count))
    				{
    					if( Addr_Flag == 1)
    					{
    						if(Data_Merge_flag == 0)
    						{
    							pui32eprom = (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << 4);
    							Data_Merge_flag=1;
    						}
    						else 
    						{
    							pui32eprom = pui32eprom | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    							if(pui32eprom > 0x59)
    							{
    								error:
    								for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++)
    								{
    									g_pui8USBTxBuffer[ui32WriteIndex] = Error_data[Error_Data_Index];
    								}
    								goto end;
    							}
    							pui32Data[Rx_Arr_Index] = pui32eprom;
    							Data_Merge_flag=0;
    							goto write;
    						}	
    					}
    					
    			 if((Rx_Arr_Index>Data_count) || (Addr_Flag == 0))
    				{
    					write:
    					pui32Weprom[EEPROM_Buff_Index++]=pui32Data[Rx_Arr_Index];
    					pui32eprom = 0x00;
    				}
    			if((Rx_Arr_Index>Data_count) && (Addr_Flag == 0))
    			break;
    			}	
    		}
    							EEPROMProgram(pui32Weprom, addrdata, sizeof(pui32Weprom));
    					
    		end:
        USBBufferDataWritten(&g_sTxBuffer, ui32Count);
        return(ui32Count);
      
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	TxHandler
     * Description of the function : Handles bulk driver notifications related to the transmit channel (data to the USB host).
     * Passed parameter			   :	void *pvCBData : is the client-supplied callback pointer for this channel.
    															uint32_t ui32Event : identifies the event we are being notified about.
    															uint32_t ui32MsgValue : is an event-specific value.
    															void *pvMsgData : is an event-specific pointer.
     * Return value				     :  uint32_t : The return value is event-specific.
     ***********************************************************************************************************/
    uint32_t
    TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
              void *pvMsgData)
    {
    
        if(ui32Event == USB_EVENT_TX_COMPLETE)
        {
            g_ui32TxCount += ui32MsgValue;
        }
    
        return(0);
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	RxHandler
     * Description of the function : Handles bulk driver notifications related to the receive channel (data from the USB host).
     * Passed parameter			   :	void *pvCBData : is the client-supplied callback pointer for this channel.
    															uint32_t ui32Event : identifies the event we are being notified about.
    															uint32_t ui32MsgValue : is an event-specific value.
    															void *pvMsgData : is an event-specific pointer.
     * Return value				     :  uint32_t : The return value is event-specific.
     ***********************************************************************************************************/
    uint32_t
    RxHandler(void *pvCBData, uint32_t ui32Event,
                   uint32_t ui32MsgValue, void *pvMsgData)
    {
    
        switch(ui32Event)
        {
    
            case USB_EVENT_CONNECTED:
            {
                g_bUSBConfigured = true;
                USBBufferFlush(&g_sTxBuffer);
                USBBufferFlush(&g_sRxBuffer);
    
                break;
            }
            case USB_EVENT_DISCONNECTED:
            {
                g_bUSBConfigured = false;
                break;
            }
    
            case USB_EVENT_RX_AVAILABLE:
            {
                tUSBDBulkDevice *psDevice;
    
                psDevice = (tUSBDBulkDevice *)pvCBData;
    
                return(EchoNewDataToHost(psDevice, pvMsgData, ui32MsgValue));
            }
    
            case USB_EVENT_SUSPEND:
            case USB_EVENT_RESUME:
            {
                break;
            }
    
            default:
            {
                break;
            }
        }
    
        return(0);
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	USB_Code
     * Description of the function : This is the main application entry function.
     * Passed parameter			   : None.
     * Return value				     :  integer value.
     ***********************************************************************************************************/
    int
    USB_Code(void)
    {
        volatile uint32_t ui32Loop;
    	
        ROM_FPULazyStackingEnable();
    
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
    		SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
    	
    		EEPROMInit();
    		
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 );
    
        g_bUSBConfigured = false;
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    
        ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
        ROM_SysTickIntEnable();
        ROM_SysTickEnable();
    		
        USBBufferInit(&g_sTxBuffer);
        USBBufferInit(&g_sRxBuffer);
    
        USBStackModeSet(0, eUSBModeForceDevice, 0);
    
        USBDBulkInit(0, &g_sBulkDevice);
    
        while(1)
        {
        }
    }
    
    /***********************************************************************************************************
     * File Name 			   :  main.c
     * Description of the File :  
     * Author				   : 
     ***********************************************************************************************************/
    #include "inc/tm4c123gh6pm.h"
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/timer.h"
    #include "driverlib/rom.h"
    #include "driverlib/usb.h"
    #include "usblib/usblib.h"
    #include "usblib/usb-ids.h"
    #include "usblib/device/usbdevice.h"
    #include "usblib/device/usbdbulk.h"
    //#include "utils/ustdlib.h"
    #include "usb_bulk_structs.h"
    #include "driverlib/eeprom.h"
    #include "usb_dev_bulk.h"
    #include "ADC_TM4C123.h"
    #include "ADC_TM4C123G.h"
    
    int main(void)
    {	
    	if(adc_value(0x04) > 0x935)
    	{
    		USB_Code(); 
    	}
    	if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
    	{
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
    	}
    	else
    	{
    		GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
    	}	
    
    }
    
    
    
    
    

  • Hello Mamatha

    I ran the code with the string 04003111213 and I see that for Block-1 Offset-0,1,2 the data is correctly reflecting in the EEPROM

    How are you checking if the data is correct?

    Regards

    Amit

  • Hi,

    I am checking the EEPROM contents in debugging session, that is by using memory window(with address 0x400af000). As it is showing only upto 16 bytes(0-15), in other code(project) i am only reading the EEPROM data by using the below code for more than 16 bytes..

    addr = 0x000;
    EEPROMRead(pui32Read, addr, sizeof(pui32Read));

    addr = 0x018;
    EEPROMRead(pui32Read1, addr, sizeof(pui32Read1));

    addr = 0x034;
    EEPROMRead(pui32Read2, addr, sizeof(pui32Read2));

    addr = 0x054;
    EEPROMRead(pui32Read2, addr, sizeof(pui32Read3));

    addr = 0x078;
    EEPROMRead(pui32Read2, addr, sizeof(pui32Read4));

    like this i am doing.. Is this the correct way ? If not please tell me how are you able read the correct output?

    With only one address it works, if you write continuously with diff random addr it is not...

    Regards,

    Mamatha

  • Hello Mamatha

    Please make sure that when using the Memory Browser you do all the steps that the EEPROMRead API would do to read the memory. As it is an indirect access method of EEPROM in TM4C devices, you need to make sure that the memory browser is not kept in "Auto-Refresh". Also when you want to read from the EEPROM, make sure that the Block and Offset registers are correctly set.

    The Second method of EEPROMRead is the correct method. You can add this check to your code to make sure that when you read the data from EEPROM Locations just programmed it matches the variables that you get from USB

    Regards

    Amit

  • Yeah i was doing that earlier, after writing the data into eeprom, i was reading that data back and able to send back the data to usb application. But while reading in the separate project(with one eeprom read) i am not getting the correct output.

    are you able to read all data which is been written with random addresses??

    Regards,

    Mamatha

  • Hello Mamatha,

    I have not tested every location using random address in context of your program, However I have done at least 4-5 sequences and then manually verified with the Memory browser by carefully following the read Sequence for EEPROM.

    You may want to check the context of the Read Project as a read in the application is working with USB getting the data.

    The Sequence you have is correct for reading from the EEPROM.

    Regards

    Amit

  •  Hi Amit,

    Can you please tell me where to check whether the memory browser  of keil is kept in "Auto-Refresh"  mode or not. And in the memory window i can see only 15 bytes, how to check for the other bytes? Can you plz tell me the correct read sequence of EEPROM read what you are following? 

    If i am writing data in the contiguous memory, i am able to read all data, but with diff address(by giving spaces in b/w), as am not able to read the data i don't know whether it is writing or not.

    Regards,

    Mamatha 

  • Hi Amit,

    With the single read starting from addr 000 i am able to read the contents which i wrote at random or linear addresses now.

    uint32_t addr;
    uint32_t pui32Read[250];

    addr = 0x000;
    EEPROMRead(pui32Read, addr, sizeof(pui32Read));

    It is fine, but i want to know how to check the data more than 16(0-F) words in memory window?? Is that possible??

    Regards,

    Mamatha

  • Hello Mamatha,

    As I mentioned the EEPROM is an indirect access method. You can do more than 1 word at a time in the debugger memory window.

    Regards

    Amit

  • Hi Amit,

    Still i am not able to write/read from these memory locations properly,

    1.000,050,020,09c,0b4,f00,fc0,ff0

    2.f00,f10,f20,f30,f40

    3.f00,f18,f30,f58

    4.c00,c20,c40,c50

    5.b00,b20,b40,b50

    6.d00,d10,d20,d30,d40

    7.000,a00,b00,c00,d00,e00,f00

    example:

    can you check with these locations, and let me know whether  you are able to get correct output?Please check my code also, because i am able to read the data with address sequence shown below but not with the above addresses,

    1.000,028,0a0,0c8

    2.000,064,0f0,1f4,2d0

    3.000,020,050,09c,0b4

    4.100,110,120,130

    5.000,100,200,300,400

    Please check and reply.

    Regards,

    Mamatha

  • Hello Mamatha,

    a> You will have to split the exact instructions you want me to try?

    b> Also since your EEPROM Read Program is different that the usb_bulk_device, and you want to check the memory browser for the correct values, you would need to specify what I need to try for what steps in (a)

    Regards

    Amit

  • Hi,

    Check with this part of the code Amit,

    static uint32_t
    EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data,
    uint32_t ui32NumBytes)
    {

    uint32_t ui32Loop, ui32Space, ui32Count;
    uint32_t ui32ReadIndex;
    uint32_t ui32WriteIndex;
    tUSBRingBufObject sTxRing;
    unsigned char Data_Merge_flag=0,Data_count=0,Addr_shift_Cnt=8,Rx_Arr_Index=0,EEPROM_Buff_Index=0,Addr_Flag=0,Error_Data_Index=0;
    uint32_t pui32eprom = 0x00;
    short int addrdata=0x00;
    uint32_t pui32Weprom[64]={0x00};

    USBBufferInfoGet(&g_sTxBuffer, &sTxRing);

    ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer);

    ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes;
    ui32Count = ui32Loop;

    g_ui32RxCount += ui32NumBytes;

    ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer);
    ui32WriteIndex = sTxRing.ui32WriteIndex;

    for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    {
    pui32Data[Rx_Arr_Index] = g_pui8USBRxBuffer[ui32ReadIndex];

    ui32ReadIndex++;
    ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ?
    0 : ui32ReadIndex;
    }

    for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    {

    if(Rx_Arr_Index<0x03)
    {
    addrdata = addrdata | (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << Addr_shift_Cnt);
    Addr_shift_Cnt = Addr_shift_Cnt - 4;
    if(Rx_Arr_Index == 0x02)
    {
    if((addrdata < 0x000) || (addrdata > 0xfff))
    {
    //goto error;
    }
    if((addrdata >= 0x000) && (addrdata <= 0x0f0))
    Addr_Flag = 1;
    }
    }
    if(Rx_Arr_Index==0x04)
    {
    Data_count = (Ascii_To_Num(pui32Data[Rx_Arr_Index-1]) << 4) | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    if(Addr_Flag == 1)
    {
    Data_count = (Data_count * 0x02)+0x04;
    }
    else
    {
    Data_count = Data_count +0x04;
    }
    }

    if((Rx_Arr_Index>=0x05)&&(Rx_Arr_Index<=Data_count))
    {
    if( Addr_Flag == 1)
    {
    if(Data_Merge_flag == 0)
    {
    pui32eprom = (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << 4);
    Data_Merge_flag=1;
    }
    else
    {
    pui32eprom = pui32eprom | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    if(pui32eprom > 0x59)
    {
    //error:
    //for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++)
    //{
    //g_pui8USBTxBuffer[ui32WriteIndex] = Error_data[Error_Data_Index];
    //}
    goto end;
    }
    pui32Data[Rx_Arr_Index] = pui32eprom;
    Data_Merge_flag=0;
    goto write;
    }
    }

    if((Rx_Arr_Index>Data_count) || (Addr_Flag == 0))
    {
    write:
    pui32Weprom[EEPROM_Buff_Index++]=pui32Data[Rx_Arr_Index];
    pui32eprom = 0x00;
    }
    if((Rx_Arr_Index>Data_count) && (Addr_Flag == 0))
    break;
    }
    }
    EEPROMProgram(pui32Weprom, addrdata, sizeof(pui32Weprom));
    EEPROMRead(pui32Reprom, addrdata, sizeof(pui32Reprom));
    for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++)
    {
    g_pui8USBTxBuffer[ui32WriteIndex] = pui32Reprom[Error_Data_Index];//Here it ll be able to read contents and send back to application for the adsress>0f0(not for <0f0 because i have merged 2 char into 1 byte)... 
    }

    end:
    USBBufferDataWritten(&g_sTxBuffer, ui32Count);
    return(ui32Count);

    }

    To read the contents of EEPROM i am using below code,

    #include "inc/tm4c123gh6pm.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include <stdio.h>
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/eeprom.h"

    uint32_t addr;
    uint32_t pui32Data[3]={1,2,3},pui32Data1[3]={4,5,6},pui32Data2[3]={7,8,9},pui32Data3[3]={10,11,12},pui32Data4[3]={13,14,15};
    uint32_t pui32Read[3],pui32Read1[3],pui32Read2[3],pui32Read3[3],pui32Read4[3],pui32Read5[3];
    int main()
    {

    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);

    EEPROMInit();

    addr = 0xd00;

    EEPROMRead(pui32Read, addr, sizeof(pui32Read));
    SysCtlDelay(200000);

    addr = 0xd10;
    EEPROMRead(pui32Read1, addr, sizeof(pui32Read1));
    SysCtlDelay(200000);

    addr = 0xd20;
    EEPROMRead(pui32Read2, addr, sizeof(pui32Read2));
    SysCtlDelay(200000);

    addr = 0xd30;
    EEPROMRead(pui32Read3, addr, sizeof(pui32Read3));

    addr = 0xd40;

    EEPROMRead(pui32Read4, addr, sizeof(pui32Read4));

    addr = 0xd50;
    EEPROMRead(pui32Read5, addr, sizeof(pui32Read5));
    return 0;
    }

    Please check and let me know where i am doing mistake? 

    3716.usb_dev_bulk.c
    /***********************************************************************************************************
     * File Name 			   :  usb_dev_bulk.c
     * Description of the File :  This header file holds the functions of USB.
     * Author				   :  Testamatic Systems
     ***********************************************************************************************************/
    
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/timer.h"
    #include "driverlib/rom.h"
    #include "usblib/usblib.h"
    #include "usblib/usb-ids.h"
    #include "usblib/device/usbdevice.h"
    #include "usblib/device/usbdbulk.h"
    #include "utils/ustdlib.h"
    #include "usb_bulk_structs.h"
    #include "driverlib/eeprom.h"
    #include "ADC_TM4C123G.h"
    #include "ADC_TM4C123.h"
    
    //*****************************************************************************
    // The system tick rate expressed both as ticks per second and a millisecond
    // period.
    //*****************************************************************************
    #define SYSTICKS_PER_SECOND     100
    #define SYSTICK_PERIOD_MS       (1000 / SYSTICKS_PER_SECOND)
    
    //*****************************************************************************
    // The global system tick counter.
    //*****************************************************************************
    volatile uint32_t g_ui32SysTickCount = 0;
    
    //*****************************************************************************
    // Variables tracking transmit and receive counts.
    //*****************************************************************************
    volatile uint32_t g_ui32TxCount = 0;
    volatile uint32_t g_ui32RxCount = 0;
    
    //*****************************************************************************
    //
    // Flags used to pass commands from interrupt context to the main loop.
    //
    //*****************************************************************************
    #define COMMAND_PACKET_RECEIVED 0x00000001
    #define COMMAND_STATUS_UPDATE   0x00000002
    
    volatile uint32_t g_ui32Flags = 0;
    uint32_t pui32Data[256];
    unsigned char Error_data[5]={0x77,0x72,0x6F,0x6E,0x67};//"wrong data";
    uint32_t pui32Reprom[64]={0x00};
    //*****************************************************************************
    // Global flag indicating that a USB configuration has been set.
    //*****************************************************************************
    static volatile bool g_bUSBConfigured = false;
    
    //*****************************************************************************
    // Interrupt handler for the system tick counter.
    //*****************************************************************************
    void
    SysTickIntHandler(void)
    {
        g_ui32SysTickCount++;
    }
    /***********************************************************************************************************
     * Function Name 			   :	Ascii_To_Num
     * Description of the function : This function is used to convert hex values into actual numbers.
     * Passed parameter			   :	Rx_Data
     * Return value				     :  Rx_Data
     ***********************************************************************************************************/
    int Ascii_To_Num(int Rx_Data)
    {
    					if((Rx_Data >= 0x30) && (Rx_Data <= 0x39))
    					{
    						Rx_Data = Rx_Data - 0x30;
    					}
    					else if((Rx_Data >= 0x61) && (Rx_Data <= 0x66 )) 
    					{
    						switch(Rx_Data)
    						{
    							case 0x61 :
    											Rx_Data = 0x0A;
    											break;
    							case 0x62 :
    											Rx_Data = 0x0B;
    											break;
    							case 0x63 :
    											Rx_Data = 0x0C;
    											break;
    							case 0x64 :
    											Rx_Data = 0x0D;
    											break;
    							case 0x65 :
    											Rx_Data = 0x0E;
    											break;
    							case 0x66 :
    											Rx_Data = 0x0F;
    											break;
    						}
    					}
      return Rx_Data;
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	EchoNewDataToHost
     * Description of the function : Receive new data and echo it back to the host.
     * Passed parameter			   :	tUSBDBulkDevice *psDevice : instance data for the device whose data is to be processed.
    															uint8_t *pui8Data : points to the newly received data in the USB receive buffer.
    															uint32_t ui32NumBytes : is the number of bytes of data available to be processed.
     * Return value				     :  static uint32_t ui32Count : is the number of bytes of data processed.
     ***********************************************************************************************************/
    
    static uint32_t
    EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data,
                      uint32_t ui32NumBytes)
    {
    
        uint32_t ui32Loop, ui32Space, ui32Count;
        uint32_t ui32ReadIndex;
        uint32_t ui32WriteIndex;
        tUSBRingBufObject sTxRing;
    		unsigned char Data_Merge_flag=0,Data_count=0,Addr_shift_Cnt=8,Rx_Arr_Index=0,EEPROM_Buff_Index=0,Addr_Flag=0,Error_Data_Index=0;
    		uint32_t	pui32eprom = 0x00;
    	  short int addrdata=0x00;
    		uint32_t pui32Weprom[64]={0x00};
    
        USBBufferInfoGet(&g_sTxBuffer, &sTxRing);
    
        ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer);
    
        ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes;
        ui32Count = ui32Loop;
    
        g_ui32RxCount += ui32NumBytes;
    
        ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer);
        ui32WriteIndex = sTxRing.ui32WriteIndex;
    	
    			for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    			{
    				pui32Data[Rx_Arr_Index]	=	g_pui8USBRxBuffer[ui32ReadIndex];
    			
    				ui32ReadIndex++;
    				ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ?
                            0 : ui32ReadIndex;			
    			}
    					
    			for(Rx_Arr_Index=0x00;Rx_Arr_Index<ui32Loop;Rx_Arr_Index++)
    			{
    				
    				if(Rx_Arr_Index<0x03)
    				{
    					addrdata = addrdata | (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << Addr_shift_Cnt);
    					Addr_shift_Cnt = Addr_shift_Cnt - 4;
    					if(Rx_Arr_Index == 0x02)
    					{
    							if((addrdata < 0x000) || (addrdata > 0xfff))
    							{
    									goto error;
    							}
    						if((addrdata >= 0x000) && (addrdata <= 0x0f0))
    							Addr_Flag = 1;
    					}
    				}
    			  if(Rx_Arr_Index==0x04)
    			  {
    					Data_count = (Ascii_To_Num(pui32Data[Rx_Arr_Index-1]) << 4) | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    					if(Addr_Flag == 1)
    					{
    					Data_count = (Data_count * 0x02)+0x04;
    					}
    					else
    					{
    						Data_count = Data_count +0x04;
    					}
    			  }
    								
    				if((Rx_Arr_Index>=0x05)&&(Rx_Arr_Index<=Data_count))
    				{
    					if( Addr_Flag == 1)
    					{
    						if(Data_Merge_flag == 0)
    						{
    							pui32eprom = (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << 4);
    							Data_Merge_flag=1;
    						}
    						else 
    						{
    							pui32eprom = pui32eprom | Ascii_To_Num(pui32Data[Rx_Arr_Index]);
    							if(pui32eprom > 0x59)
    							{
    								error:
    								for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++)
    								{
    									g_pui8USBTxBuffer[ui32WriteIndex] = Error_data[Error_Data_Index];
    								}
    								goto end;
    							}
    							pui32Data[Rx_Arr_Index] = pui32eprom;
    							Data_Merge_flag=0;
    							goto write;
    						}	
    					}
    					
    			 if((Rx_Arr_Index>Data_count) || (Addr_Flag == 0))
    				{
    					write:
    					pui32Weprom[EEPROM_Buff_Index++]=pui32Data[Rx_Arr_Index];
    					pui32eprom = 0x00;
    				}
    			if((Rx_Arr_Index>Data_count) && (Addr_Flag == 0))
    			break;
    			}	
    		}
    							EEPROMProgram(pui32Weprom, addrdata, sizeof(pui32Weprom));
    			        EEPROMRead(pui32Reprom, addrdata, sizeof(pui32Reprom));
    								for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++)
    								{
    									g_pui8USBTxBuffer[ui32WriteIndex] = pui32Reprom[Error_Data_Index];
    								}		
    					
    		end:
        USBBufferDataWritten(&g_sTxBuffer, ui32Count);
        return(ui32Count);
      
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	TxHandler
     * Description of the function : Handles bulk driver notifications related to the transmit channel (data to the USB host).
     * Passed parameter			   :	void *pvCBData : is the client-supplied callback pointer for this channel.
    															uint32_t ui32Event : identifies the event we are being notified about.
    															uint32_t ui32MsgValue : is an event-specific value.
    															void *pvMsgData : is an event-specific pointer.
     * Return value				     :  uint32_t : The return value is event-specific.
     ***********************************************************************************************************/
    uint32_t
    TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
              void *pvMsgData)
    {
    
        if(ui32Event == USB_EVENT_TX_COMPLETE)
        {
            g_ui32TxCount += ui32MsgValue;
        }
    
        return(0);
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	RxHandler
     * Description of the function : Handles bulk driver notifications related to the receive channel (data from the USB host).
     * Passed parameter			   :	void *pvCBData : is the client-supplied callback pointer for this channel.
    															uint32_t ui32Event : identifies the event we are being notified about.
    															uint32_t ui32MsgValue : is an event-specific value.
    															void *pvMsgData : is an event-specific pointer.
     * Return value				     :  uint32_t : The return value is event-specific.
     ***********************************************************************************************************/
    uint32_t
    RxHandler(void *pvCBData, uint32_t ui32Event,
                   uint32_t ui32MsgValue, void *pvMsgData)
    {
    
        switch(ui32Event)
        {
    
            case USB_EVENT_CONNECTED:
            {
                g_bUSBConfigured = true;
                USBBufferFlush(&g_sTxBuffer);
                USBBufferFlush(&g_sRxBuffer);
    
                break;
            }
            case USB_EVENT_DISCONNECTED:
            {
                g_bUSBConfigured = false;
                break;
            }
    
            case USB_EVENT_RX_AVAILABLE:
            {
                tUSBDBulkDevice *psDevice;
    
                psDevice = (tUSBDBulkDevice *)pvCBData;
    
                return(EchoNewDataToHost(psDevice, pvMsgData, ui32MsgValue));
            }
    
            case USB_EVENT_SUSPEND:
            case USB_EVENT_RESUME:
            {
                break;
            }
    
            default:
            {
                break;
            }
        }
    
        return(0);
    }
    
    /***********************************************************************************************************
     * Function Name 			     :	USB_Code
     * Description of the function : This is the main application entry function.
     * Passed parameter			   : None.
     * Return value				     :  integer value.
     ***********************************************************************************************************/
    int
    USB_Code(void)
    {
        volatile uint32_t ui32Loop;
    	
        ROM_FPULazyStackingEnable();
    
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
    		SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
    	
    		EEPROMInit();
    		
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
        ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 );
    
        g_bUSBConfigured = false;
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    
        ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
        ROM_SysTickIntEnable();
        ROM_SysTickEnable();
    		
        USBBufferInit(&g_sTxBuffer);
        USBBufferInit(&g_sRxBuffer);
    
        USBStackModeSet(0, eUSBModeForceDevice, 0);
    
        USBDBulkInit(0, &g_sBulkDevice);
    
        while(1)
        {
    
        }
    }
    /***********************************************************************************************************
                                           Revision History 
    									                    *----------------*
    
      Version    Created/Modified by    Created/Modified Data     Description of Changes
      -------	   -------------------    ---------------------		  ----------------------
    	1.0	       Mamatha M		           23-8-2014			          Initial creation of usb_dev_bulk.c for USB
    
    ***********************************************************************************************************/
    
    

    Regards,

    Mamatha.

  • Hello Mamtha,

    The internal EEPROM is 2KB. That means the max address is 0x7FC. In the case above you are trying to access 0xD00 onwards address which is outside the range.

    Regards

    Amit

  • Hi,

    Yeah Amit, that is true but how i am able to write into these locations(D10,D20,..), and get back the data in this code? 

    addr = 0xd00;
    EEPROMProgram(pui32Data, addr, sizeof(pui32Data));

    addr = 0xd00;
    EEPROMRead(pui32Read, addr, sizeof(pui32Read));

    addr = 0xd10;
    EEPROMProgram(pui32Data1, addr, sizeof(pui32Data1));

    addr = 0xd10;
    EEPROMRead(pui32Read1, addr, sizeof(pui32Read1));

    addr = 0xd20;
    EEPROMProgram(pui32Data2, addr, sizeof(pui32Data2));

    addr = 0xd20;
    EEPROMRead(pui32Read2, addr, sizeof(pui32Read2));

    (0x400A.F000-0x400A.FFFF EEPROM and Key Locker, 540)

    Total range is from 400AF000-400AFFFF, in this what address range is reserved for EEPROM data write?

    Regards,

    Mamatha

  • Hell Mamatha,

    The total address range is the mapping of the EEPROM Control Register. It has no-corelation to the number of words/bytes the EEPROM is made up of as I have mentioned earlier that it is a indirect access. I suspect it is doing a wrap around of the EEPROM Data or reading/programming the last location only as the address is more than the range.

    Regards

    Amit

  • Hi Amit,

    I have last question pending,

    when i am trying to write the EEPROM with this addr sequence (000,020,010,040,030,050,060,070), it is not writing to 020 and 040th location, can you please check it .. Do we need to write these locations in order or is threre any other reason?

    Regards,

    Mamatha

  • Hello Mamatha,

    The issue is in the code you have declared EEPROMProgram to program the words in the full array pui32Weprom and the size given is that of the array and not what the user is entering,

    The same should be changed from

    EEPROMProgram(pui32Weprom, addrdata, sizeof(pui32Weprom));
    to

    EEPROMProgram(pui32Weprom, addrdata, (UserCount*0x4));

    where the UserCount is the second parameter in the string mentioning the number of words

    Regards

    Amit

  • Hi,

    Now it is working Amit, Thank you so much for your help  :-)...

    Regards,

    Mamatha M

  • Hi Metin,


    Thanks for developing and sharing this code, it is very helpful!


    I have one question about something I am not understanding. You are writing the string "Hello World" as value4, however the variable is defined as uint8_t. First, I didn't know this was possible.


    Secondly, if I have some string collected from a user interface, how could I store it to EEPROM? For instance, I have a string timestamp, defined this way:

    char timestamp[9] = "16:52:32";

    Then, I re-wrote this line from your code thusly:

    struct E2PROM e2prom_write_value = {5,7,9826, timestamp}; /* Write struct */

    Of course, this gives me an error since a char is not a uint8_t. I try to cast the type:

    struct E2PROM e2prom_write_value = {5,7,9826, (uint8_t) timestamp}; /* Write struct */

    But this gives warnings (no errors) and doesn't behave as expected.

    When I try and change the struct definition from uint8_t to char (to match my string) it writes gibberish instead of my stored value.
    Any pointers?

    Thanks,

    Lee

  • Hello, Where can I download the functions used in this code? Such as the function body of EEPROMBlockCountGet(), EEPROMRead, EEPROMSizeGet()... Thank you
  • Hi, you need the TM4C software package, available here: software-dl.ti.com/.../index_FDS.html

  • Hi,

    To read a variable stored in the eeprom and to write to the variable after incrementing, I did program as shown below. But it is not working. What modifications should I do to make it work?

    #define E2PROM_TEST_ADRES 0x0
    struct E2PROM
    {
        uint8_t value1;
      };

    struct E2PROM e2prom_read_value;

    int main(void)
    {
        uint32_t *st;
        uint32_t returnCode;
        SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);
        do
         {
             returnCode=EEPROMInit(); // EEPROM start
         }
        while(returnCode!=EEPROM_INIT_OK);

        EEPROMIntDisable(EEPROM_INT_PROGRAM);
        EEPROMBlockProtectSet(0,0x0);
        EEPROMRead((uint32_t *)&e2prom_read_value, E2PROM_TEST_ADRES, sizeof(e2prom_read_value));
        st=(uint32_t *)&e2prom_read_value;
       *st++;
        EEPROMProgram(st, E2PROM_TEST_ADRES, sizeof(st));

    Regards

    Sandra