Pinguino Forum

Full Version: Accessing registers/interrupts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
You get it...:-D

And how about the registers? Is there a way to access them?
The I/O ports or the CPU's registers? The C compiler uses the CPU ones and I'm not clear why you'd want to.

Uhm, sorry for the late answer. The syntax in my first post in this thread works now. The rest is well explained in the data sheet and in app notes. Thx so far.

I have 2 issues I am currently facing may be you can help me:

Issue 1:

Reading out the receive buffer of I2C bus 2.

Currently, I want to connect my Raspberry Pi B+ to the PIC32MX220, which works quite good since they find each other and the RPI can write to receive buffer indicated by a green LED blinking when data has been written to the receive buffer. The problem is now to read out this buffer and my guess would be just assigning the I2C2RCV to a variable (see code below). I found code examples in the web, where this syntax has been used, but the compiler does't like this.

Here is the link with the code example:

Here the stdout:
if exist C:\pinguino-11\user\source\main32.o @del C:\pinguino-11\user\source\main32.o
if exist C:\pinguino-11\user\source\main32.elf @del C:\pinguino-11\user\source\main32.elf
if exist C:\pinguino-11\user\source\main32.hex @del C:\pinguino-11\user\source\main32.hex
if exist C:\pinguino-11\user\source\obj\non-free\processor.o @del C:\pinguino-11\user\source\obj\non-free\processor.o
C:\pinguino-11\compilers\p32\bin\p32-gcc.exe -march=m4k -EL -msoft-float -nostdlib -static -O3 -minterlink-mips16 -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-LC:\pinguino-11\user\source\obj\non-free -Wl,--defsym,_min_heap_size=512 -Wl,-Map=C:\pinguino-11\user\source\ -D __PIC32MX__ -D __32MX220F032D__ -D PIC32_PINGUINO_220 -TC:\pinguino-11\p32\lkr\32MX220F032D.ld -TC:\pinguino-11\p32\lkr\elf32pic32mx.x -LC:\pinguino-11\user\source\obj\non-free\usb -lm -lgcc -lc -fdollars-in-identifiers -IC:\pinguino-11\p32\include\non-free -IC:\pinguino-11\p32\include\pinguino\core -IC:\pinguino-11\p32\include\pinguino\libraries -IC:\pinguino-11\p32\lkr -IC:/Users/-/Documents/Dies_und_das/PIC32_PINGUINO_MX220/dobby -IC:\pinguino-11\user\source\obj\non-free -mips16 -S -o C:\pinguino-11\user\source\main32.S C:\pinguino-11\user\source\main32.c
C:\pinguino-11\compilers\p32\bin\p32-gcc.exe -march=m4k -EL -msoft-float -nostdlib -static -O3 -minterlink-mips16 -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-LC:\pinguino-11\user\source\obj\non-free -Wl,--defsym,_min_heap_size=512 -Wl,-Map=C:\pinguino-11\user\source\ -D __PIC32MX__ -D __32MX220F032D__ -D PIC32_PINGUINO_220 -TC:\pinguino-11\p32\lkr\32MX220F032D.ld -TC:\pinguino-11\p32\lkr\elf32pic32mx.x -LC:\pinguino-11\user\source\obj\non-free\usb -lm -lgcc -lc -fdollars-in-identifiers -IC:\pinguino-11\p32\include\non-free -IC:\pinguino-11\p32\include\pinguino\core -IC:\pinguino-11\p32\include\pinguino\libraries -IC:\pinguino-11\p32\lkr -IC:/Users/-/Documents/Dies_und_das/PIC32_PINGUINO_MX220/dobby -IC:\pinguino-11\user\source\obj\non-free -mips16 -E C:\pinguino-11\user\source\main32.c > C:\pinguino-11\user\source\main32.pp
C:\pinguino-11\compilers\p32\bin\p32-gcc.exe -march=m4k -EL -msoft-float -nostdlib -static -O3 -minterlink-mips16 -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-LC:\pinguino-11\user\source\obj\non-free -Wl,--defsym,_min_heap_size=512 -Wl,-Map=C:\pinguino-11\user\source\ -D __PIC32MX__ -D __32MX220F032D__ -D PIC32_PINGUINO_220 -TC:\pinguino-11\p32\lkr\32MX220F032D.ld -TC:\pinguino-11\p32\lkr\elf32pic32mx.x -LC:\pinguino-11\user\source\obj\non-free\usb -lm -lgcc -lc -fdollars-in-identifiers -IC:\pinguino-11\p32\include\non-free -IC:\pinguino-11\p32\include\pinguino\core -IC:\pinguino-11\p32\include\pinguino\libraries -IC:\pinguino-11\p32\lkr -IC:/Users/-/Documents/Dies_und_das/PIC32_PINGUINO_MX220/dobby -IC:\pinguino-11\user\source\obj\non-free -mips16 -c -g -Wa,-a,-ad C:\pinguino-11\user\source\main32.c > C:\pinguino-11\user\source\main32.lst
C:\Users\-\AppData\Local\Temp\ccspqKZc.s: Assembler messages:
C:\Users\-\AppData\Local\Temp\ccspqKZc.s:10864: Error: internal error: fixup not contained within frag
C:\Users\-\AppData\Local\Temp\ccspqKZc.s:10970: Error: internal error: fixup not contained within frag
make: *** [compile] Error 1

Issue 2:

Modifing the PIC slave address.

I would like to use an individual slave address without using the slave address masking, where bits just set to don't care. Due to the informations in the datasheet (p.174) it should be possible to write to the I2CxADD register, but an assignment like
I2C2ADD = 0x0E;
will be ignored. It still responds to the default address. Has anyone tried this before or can verify that it should work?

For completeness here my code:
#include <i2c.c>

#define PIC_ADDR 0x0E

void blinkGreen(void)
digitalWrite(13, HIGH);
digitalWrite(13, LOW);

void blinkRed(void)
digitalWrite(9, HIGH);
digitalWrite(9, LOW);

void setup() {
//    I2C.init(I2C2, I2C_SLAVE_MODE, I2C_100KHZ);
   I2C2ADD = PIC_ADDR;        //<---- seems to be ignored
   I2C2MSK = 0;
   pinMode(13, OUTPUT);
   pinMode(9, OUTPUT);
   digitalWrite(13, LOW);
   digitalWrite(9, LOW);

void loop() {
   if (I2C2STATbits.D_A) {
       u8 data;
       if (I2C2STATbits.RBF){
       data = I2C2RCV;        //<---- Produce the error
   else blinkRed();

Issue 1:

Please edit sources/ got to the compile: rule and delete line :

    $(CC) $(ELF_FLAGS) $(LDFLAGS) $(CFLAGS) $(MIPS16_OPT) -c -g -Wa,-a,-ad $(_IDE_SRCDIR_)\main32.c > $(_IDE_SRCDIR_)\main32.lst

Issue 2:

Do you get an error message or it just doesn't work ?
Thx, Regis. Unfortunately, issue 1 still exists after deleting the line you mentioned. Is there a possibilty to prevent the deleting of the temporary file ccspqKZc.s on my side? Then I could upload the file and maybe it shows what is going wrong.

Regarding issue 2 it is not an error message. I played it a bit around and found out, that the PIC prints the correct address when using

CDC.printf("Pic address: 0x%X \r\n", I2C2ADD);

But when I use i2cdetect on raspi side it shows me still 0x03 instead of 0x0E and the most confusing thing is, that the PIC is really responding on 0x03. Maybe raspi handels the address different, but why it should do that?
Please send me your program and will try to compile it on my computer.
Here is the .pde, but it is just the code I posted above. If mean the code from raspi side, I attached it too.
Here is what I get :

/usr/bin/../lib/gcc/mips-elf/4.9.2/../../../../mips-elf/bin/ld: region `kseg0_program_mem' overflowed by 628 bytes

The program is simply to big for your PIC32MX220 because the HID bootloader, the CDC library and the printf function are quite big.
You can't do anything about the bootloader but you could try to use Serial instead of CDC and print/printNumber instead of printf.
For example, if I replace :

CDC.printf("Pic address: 0x%X \r\n", I2C2ADD);

with :

CDC.print("Pic address: 0x");
CDC.printNumber(I2C2ADD, HEX);

I don't have any error anymore and the code size is 14268 / 16368 bytes (87% used).

If I now replace CDC with Serial then the code size is 9052 / 16368 bytes (55% used).

Last, if I compile the code with MIPS16 option, Serial and print/printNumber functions I get : 6792 / 16368 bytes (41% used).

Now you have 10K free Smile .
Pages: 1 2 3