|
|
View previous topic :: View next topic |
Author |
Message |
dnz_1905
Joined: 31 Mar 2011 Posts: 2
|
Read data from ROM and send with USB problem |
Posted: Sun May 15, 2011 12:47 pm |
|
|
Dear All,
I searched the forum and tried the suggestions but I can not manage to succeed. I want to read the datas from ROM and then send these datas to PC via USB. But when I send them,the received datas are different from the sent datas. I am suspicious that I write the datas correctly to ROM. This is my first time to read and write datas to ROM. So I dont know the problem. What can cause this?
Thanks
Here is the code
Code: | #include <18F4550.h>
#device *=16
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN
#use delay (clock=48000000)
#define USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 64 //allocate 8 bytes in the hardware for transmission
//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 64 //allocate 8 bytes in the hardware for reception
#include <pic18_usb.h>
#include <USB.H>
#include <USB_Konfigurasyon1.h>
#include <usb.c>
#define USB_CON_SENSE_PIN PIN_C6
#define usb_attached() input(USB_CON_SENSE_PIN)
#use fast_io(a)
#use fast_io(e)
char rom sine_table[130]=// When I comment out "rom", I read correct //values on the PC
{
127, 130, 133, 136, 139, 142, 145, 148, 151, 154, 157, 160, 163, 166, 169,
172, 175, 178, 181, 184, 186, 189, 192, 195, 197, 200, 202, 205, 207, 210,
212, 214, 216, 219, 221, 223, 225, 227, 229, 230, 232, 234, 236, 237, 239,
240, 241, 243, 244, 245, 246, 247, 248, 249, 250, 250, 251, 252, 252, 253,
253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252, 252, 251, 250, 250,
249, 248, 247, 246, 245, 244, 242, 241, 240, 238, 237, 235, 234, 232, 230,
228, 226, 224, 222, 220, 218, 216, 214, 211, 209, 207, 204, 202, 199, 197,
194, 191, 189, 186, 183, 180, 178, 175, 172, 169, 166, 163, 160, 157, 154,
151, 148, 145, 142, 138, 135, 132, 129, 127, 124, 121, 118, 114, 111, 108,
105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 73, 70, 67, 64,
62, 59, 56, 54, 51, 49, 46, 44, 42, 39, 37, 35, 33, 31, 29,
27, 25, 23, 22, 20, 18, 17, 15, 14, 12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12,
13, 14, 16, 17, 19, 21, 22, 24, 26, 28, 30, 32, 34, 36, 38,
41, 43, 45, 48, 50, 53, 55, 58, 60, 63, 66, 69, 71, 74, 77,
80, 83, 86, 89, 92, 95, 98, 101, 104, 107, 110, 113, 116, 119, 122, 125
};
void usb_debug_task(void)
{
static int8 last_connected;
static int8 last_enumerated;
int8 new_connected;
int8 new_enumerated;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
if (new_connected && !last_connected)
output_e(0b00000010); //kırmızı led yanıyor. Takılı değilken
if (!new_connected && last_connected)
output_e(0b00000010);
if (!new_connected && !last_connected)
output_e(0b00000010);
if (new_enumerated && !last_enumerated)
output_e(0b00000001);
last_connected=new_connected;
last_enumerated=new_enumerated;
}
void main()
{
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_32);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
// TODO: USER CODE!!
set_tris_e(0x00);
output_e(0x00);
set_tris_a(0b00000010);
output_a(0x00);
usb_init();
while(1)
{
usb_task();
usb_debug_task();
if (usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, in_data, 64);
switch(in_data[0])
{
case 0x81:
usb_puts(1,sine_table,130,0);
default:
break;
}
}
}
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun May 15, 2011 3:36 pm |
|
|
What you show, should nearly work. There are several small bugs. You are not disabling the SPI port, have AN0 selected for analog, but it's TRIS set to '0'.
The big one though, is that 'sine_table', is _not_ the address of a CONST table. It is the address of the function returning the data, and in the ROM data space, not the RAM space. the USB_PUTS function, expects a pointer to RAM, not ROM. So you will receive the bytes in the RAM data space, corresponding to where the function 'sine_table' is in the ROM....
This is down to the PIC having two memory spaces, not a linear address space like the PC.
The 'label_address' function, will give you the actual ROM address of the table, but it'll still be in the wrong address space for the puts function.
You would basically need to copy the ROM data into a RAM buffer, before performing the write.
Going the other way will be even worse. You would have to ensure that USB transactions 'stop' for long enough for the write, and deal with reading the required blocks, changing only the bytes required, and writing these back. The memory on this chip is organised into 64 byte pages, and you must erase a whole page at a time, so if the stored table is part way through a page, you will need to read the stuff in front of the table, and write this back. Similarly at the end of the table.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|