Microcontroladores PIC en Linux.
¿Quieres reaccionar a este mensaje? Regístrate en el foro con unos pocos clics o inicia sesión para continuar.

prueva con usart.h y masterI2C.h

2 participantes

Página 1 de 2. 1, 2  Siguiente

Ir abajo

prueva con usart.h y masterI2C.h Empty prueva con usart.h y masterI2C.h

Mensaje por alejandro Vie 11 Sep 2009 - 21:47

ahora,ya que el rover serà escrito totalmente en gcbasic he comenzado ha escribir un fw de prueva entre el master(16F767) y uno de los slave(en este caso el 16F88 dedicado a la comunicaciòn con el pc a traves de un modulo radio).el codigo es este:
Código:

'******************************************************************************************
'******** CONFIGURACION DEL PIC **********************************************
'******************************************************************************************
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
#include                  'libreria I2C slave
#include                              'libreria USART
'''''''''''''''''''''''''''''''''' Setup USART module '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define USART_BAUD_RATE 600                   
#define USART_BLOCKING
'''''''''''''''''''''''''''''''''' Setup SSP module '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'          'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                            'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
InitUSART                                      'Setup USART
InitSSP                                        'Configuraciòn registros SSP y activar el interrupt 
Main:
  Interrupt                                  'En caso de interrupt
  TestLed = RxBuffer(1)                      'Recibe byte del Master
  HserPrint "Test"
  HserSend TestLed
  HserPrint "#®️"
  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 
  goto Main
el problema que me da este error:
Strumento in esecuzione: gcbasic

Great Cow BASIC (0.9 16/6/2009)

Compilando /home/alejandro/Scrivania/Robot/Rover/Firmware/16F88/Control_transmiciòn.gcb ...
Segmentation fault

Uscito: 35584
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Sáb 12 Sep 2009 - 1:41

Que tal Alejandro?

Creo que el problema está en las interrupciones.
Nosé como funciona la librería I2C que estás usando, pero creo que una forma más correcta de manejar las interrupciones es esta:

Código:

'******************************************************************************************
'******** CONFIGURACION DEL PIC **********************************************
'******************************************************************************************
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
#include                  'libreria I2C slave
#include                              'libreria USART

'Setup USART module '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define USART_BAUD_RATE 600                   
#define USART_BLOCKING

'Setup SSP module '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'          'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'byte para activar el interrupt

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                            'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out

PORTA=b'00000'                                'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down

InitUSART                                      'Setup USART
InitSSP                                        'Configuraciòn SSP, interrupt
 

Do            'Bucle principal: no hace nada

Loop          'Fin de bucle principal

Sub Interrupt                                  'Subrutina interrupciones
  TestLed = RxBuffer(1)                      'Recibe byte del Master
  HserPrint "Test"
  HserSend TestLed
  HserPrint "#®️"
  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 
End Sub


De todas formas hay un par de cosas:
- Que versión de GcBasic usas? ( al compilar te sale algo como esto: Great Cow BASIC (0.9 12/8/2009) )

- 600 baudios es muy lento, supongo que lo haces por algo, pero es demasiado lento para un reloj de 20 MHz.
Si no puedes poner una velocidad más alta, creo que deberías poner un reloj más lento.
Otra posiblidad sería utlizar rs232 por software.

- Si recibes datos por I2C muy rápidos quizás tengas problemas, porque la rutina usart es muy lenta, además tienes un retardo de 10 ms... si en ese tiempo recibes varios datos por I2C no sé si vá a funcionar bién...


Estaría muy bién que me mandaras la librería I2C y ponerla en "descargas"



Saludos.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Sáb 12 Sep 2009 - 8:04

la versiòn de GCBasic es la 0.9
Código:
'''''''''''''''''''''''''''''''''' CONFIGURACION DEL PIC ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
#include                  'libreria I2C slave
#include                              'libreria USART
'''''''''''''''''''''''''''''''''' MODULO USART '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define USART_BAUD_RATE 600                    'Configuro Vicky a 600 baud de transmiciòn

#define USART_BLOCKING
'''''''''''''''''''''''''''''''''' MODULO SSP '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'          'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                            'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
InitUSART                                      'Setup USART
InitSSP                                        'Configuraciòn registros SSP y activar el interrupt 

Sub Interrupt                                  'Subrutina interrupciones
  TestLed = RxBuffer(1)                        'Recibe byte del Master
  HserPrint "Test"
  HserSend TestLed
  HserPrint "#®️"
  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C
  Rotate TestLed Right
  PortB.3 = Status.C
  Rotate TestLed Right
  PortB.6 = Status.C
  Rotate TestLed Right
  PortB.7 = Status.C
End Sub

Do
'''''''''
Loop
da el mismo error
la velocidad de 600 baudios es por lòs modulos radios economicos.ha esa velocidad recibe bien.veremos despuès.
este es el codigo con la libreria RS232 y compila bien.
Código:
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
#include                  'libreria I2C slave
'''''''''''''''''''''''''''''''''' Setup USART module '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
InitSer 1,r600,1+WaitForStart,8,1,none,normal
'''''''''''''''''''''''''''''''''' Setup SSP module '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'          'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                            'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
InitSSP                                        'Configuraciòn registros SSP y activar el interrupt 
Main:
  Interrupt                                  'En caso de interrupt
  TestLed = RxBuffer(1)                      'Recibe byte del Master
  SerSend 1,84
  SerSend 1,101
  SerSend 1,115
  SerSend 1,116

  SerSend 1,TestLed
  SerSend 1,35
  SerSend 1,169

  wait 25 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 
  goto Main 
lo cambierò para crear la sub interrupt y el delay de la rs232
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Sáb 12 Sep 2009 - 9:51

la versiòn de GCBasic es la 0.9

Si.. pero ¿has instalado el último update?
Eso lo ves en la fecha: Great Cow BASIC (0.9 12/8/2009)

Si no lo tienes, instálalo porque se resuelven algunos problemas con las interrupciones.

Si vas a utilizar rs232 por software creo que tienes que definir los pines Rx y TX.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Sáb 12 Sep 2009 - 14:28

tenes el link?
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Sáb 12 Sep 2009 - 15:29

Código:
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
#include <SSP_I2C_PicSlave.h>                  'libreria I2C slave
#define Slv_Comunicacion b'00111100'            'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
#define USART_BAUD_RATE 600                    'Configuro a 600 baud de transmiciòn

#define USART_BLOCKING
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                              'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                  'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
InitSSP                                        'Configuraciòn registros SSP y activar el interrupt 

InitUSART

'Sub Interrupt                                  'Subrutina interrupciones
'  TestLed = RxBuffer(1)                        'Recibe byte del Master
'  HserPrint "Test"

'  HserSend TestLed

'  HserPrint "#®️"

'  wait 10 ms
'  Rotate TestLed Right
'  PortB.0 = Status.C 
'  Rotate TestLed Right
'  PortB.3 = Status.C 
'  Rotate TestLed Right
'  PortB.6 = Status.C 
'  Rotate TestLed Right
'  PortB.7 = Status.C 
'End Sub

do
  Interrupt                                    'En caso de interrupt
  TestLed = RxBuffer(1)                        'Recibe byte del Master
  HserPrint "Test"

  HserSend TestLed

  HserPrint "#®️"

  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 
loop
ahora viene compilado sin errores.tenia que poner la nueva libreria usart.h en gcbasic/include/lowlevel prueva con usart.h y masterI2C.h Icon_redface
pero el sub interrupt no.
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Sáb 12 Sep 2009 - 20:59

La última actualización de GcBasic la puedes encontrar aquí:

http://gcbasic.sourceforge.net/update.html

Cuando instales el update ya no hace falta #incluir la nueva librería usart.h porque ya viene incluida.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Dom 13 Sep 2009 - 16:34

ho instalado el update,resultado..........igual que antes.
Código:
'''''''''''''''''''''''''''''''''''''' CONFIGURACION DEL PIC '''''''''''''''''''''''''''''''''''''''''''
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#include <SSP_I2C_PicSlave.h>                  'libreria I2C slave
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'            'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
#define USART_BAUD_RATE 600                    'Configuro a 600 baud de transmiciòn

#define USART_BLOCKING
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                              'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                  'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
InitSSP                                        'Configuraciòn registros SSP y activar el interrupt 

InitUSART

Sub Interrupt                                  'Subrutina interrupciones
  TestLed = RxBuffer(1)                      'Recibe byte del Master
  HserPrint "Test"

  HserSend TestLed

  HserPrint "#®️"

  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 
End Sub

Do
''''''''''''''''''''''''''
Loop
responde
Código:
Strumento in esecuzione: gcbasic

Great Cow BASIC (0.9 16/6/2009)

Compiling /home/alejandro/Scrivania/Robot/Rover/Firmware/16F88/Control_transmiciòn.gcb ...
Segmentation fault

Uscito: 35584
en cambio con
Código:
do
  Interrupt                                    'En caso de interrupt
  TestLed = RxBuffer(1)                        'Recibe byte del Master
  HserPrint "Test"

  HserSend TestLed

  HserPrint "#®️"

  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 
loop
todo ok,estàs seguro que exixte una sub Interrupt.esa sub existe en mikrobasic.
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Dom 13 Sep 2009 - 17:40

Código:
'''''''''''''''''''''''''''''''''''''' CONFIGURACION DEL PIC '''''''''''''''''''''''''''''''''''''''''''
#chip 16f88,20
#config OSC=HS,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#include                    'libreria I2C slave
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'            'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
#define USART_BAUD_RATE 600                    'Configuro a 600 baud de transmiciòn

#define USART_BLOCKING
Dim RxBuffer(RxBufferSize) 
DIR PORTA b'00000'                              'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                  'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
InitSSP                                        'Configuraciòn registros SSP y activar el interrupt 

InitUSART

On Interrupt PORTBChange call Interrupt_I2C_Serial

Sub Interrupt_I2C_Serial                        'Subrutina interrupciones
    if PIR1.SSPIF=1 then                        'si la recedpciòn se verificò......
      TestLed=RxBuffer(1)                        'Recibe byte del Master
      HserPrint "Test"

      HserSend TestLed

      HserPrint "#®️"

      wait 10 ms
      Rotate TestLed Right
      PortB.0 = Status.C 
      Rotate TestLed Right
      PortB.3 = Status.C 
      Rotate TestLed Right
      PortB.6 = Status.C 
      Rotate TestLed Right
      PortB.7 = Status.C
    end if
    PIR1.SSPIF=0                              'Limpio el registro de interrupt del I2C
End Sub

Do
'''''''''''''''''''''''''''''''''''''''
Loop
ahora lo compila sin errores.una duda,el slave despuès de haber recibido el dato no tendria que liberar el bus metiendo el mismo bajo?
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Dom 13 Sep 2009 - 20:27

con esta modifica(mirando el datasheet) tendria que funcionar.por lo menos me compila sin problemas.
Código:
Sub Interrupt_I2C_Serial                  'Subrutina interrupciones
    if PIR1.SSPIF=1 then
      TestLed=RxBuffer(1)                        'Recibe byte del Master
      HserPrint "Test"

      HserSend TestLed

      HserPrint "#®️"

      wait 10 ms
      Rotate TestLed Right
      PortB.0 = Status.C 
      Rotate TestLed Right
      PortB.3 = Status.C 
      Rotate TestLed Right
      PortB.6 = Status.C 
      Rotate TestLed Right
      PortB.7 = Status.C
      PIR1.SSPIF=0                                'Flag de interrupt bajo,limpio el registro de interrupt del bus I2C
      SSPCON.CKP=1                            'Deja la linea SCL del bus I2C libre
    end if
End Sub
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Lun 14 Sep 2009 - 6:32

Bueno... lo primero es que creo no has instalado totalmente el último update, en Linux hay que compilar el gcbasic.bas para tener la última versión del compilador, entonces tendrás:

Código:
Great Cow BASIC (0.9 12/8/2009)
Esta versión corrige algunos bugs de versiones anteriores, por ejemplo en algunos casos de interrupciones cuando se usan arrays ( RxBuffer() ) dentro y fuera de la interrupción.

He estado mirando la librería SSP_I2C_PicSlave.h y tienes razón... hay una rutina interrupt.

Entonces yo estaba confundido, creía que esto era la subrutina de interrupciones:

Código:
  Interrupt                                    'En caso de interrupt
  TestLed = RxBuffer(1)                        'Recibe byte del Master
  HserPrint "Test"

  HserSend TestLed

  HserPrint "#®️"

  wait 10 ms
  Rotate TestLed Right
  PortB.0 = Status.C 
  Rotate TestLed Right
  PortB.3 = Status.C 
  Rotate TestLed Right
  PortB.6 = Status.C 
  Rotate TestLed Right
  PortB.7 = Status.C 

Pero nó... esta linea:
Código:
  Interrupt                                    'En caso de interrupt

Es una llamada a la subrutina interrupt que hay en la librería.

según ví en el mensaje del foro GcBasic hay que llamar a la subrutina directamente para que funcione en ese ejemplo, pero creo que eso puede ser por un problema que había con las interrupciones en algunos casos... no estoy seguro.
Pero esa librería y ese ejemplo son de hace un tiempo, habría que probar.

Entonces el código que pusiste al principio debería de compilar bién, o darte un error porque 600 baudios y reloj de 20 MHz no son compatibles en Hardware usart, para 600 baudios podrías usar 4 MHz.



Respecto a la librería:

Una cosa que no es muy buena es poner un "Sub interrupt" en una librería, porque eso puede crear conflicto si esa subrutina se crea en otro sitio, lo mejor es dejar que GcBasic gestione el tema y hacer esto:
Código:
On interrupt SSP1Ready call XXXX
Entonces GcBasic se encarga de todo y no hay conflictos.

Otra cosa no muy buena de la librería es esto:
Código:
Sub Interrupt 
    FlagCheck:
    If SSPIF Off Then goto FlagCheck
 
Porque si vás a usar otras interrupciones eso es un bucle sin fin...
Pero si es una interrupcion SSP no parece que tenga mucho sentido quedarse esperando a SSPIF.

Entonces si solo vas a usar el pic con esa librería para I2C slave no hay problema, pero si quieres hacer otras cosas entonces puede haber conflictos.

Creo que una forma mejor podría ser esta:
En la librería SSP_I2C_PicSlave.h,
En: Sub InitSSP
Cambiar esto:
Código:
    ;Setup Interrupt
    PIR1 = 0
    index = 0
    Set SSPIE On ;Enable SSP peripheral interrupt
    Set PEIE On ;Enable all peripheral interrupts
    Set GIE On ;Enable global interrupts

Por esto:
Código:
    ;Setup Interrupt
    On interrupt SSP1Ready call SlaveStatus

Y eliminar la Sub interrupt:
Código:
Sub Interrupt 
    FlagCheck:
    If SSPIF Off Then goto FlagCheck
    Set SSPIF Off ;Clear SSP flag
    SlaveStatus ;Sub to check SSP status bits
End Sub

Y Gcbasic se encarga de activar las interrupciones y de llamar a SlaveStatus cuando hay una interrupcion SSP, y tambien de borrar el flag SSPIF.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Lun 14 Sep 2009 - 10:28

Una cosa... si instalaste gcbasic con el paquete .deb desargado de aquí entonces no tienes que compilar nada, solo descarga el paquete actiualizado e instálalo: gcbasic.deb

Si quieres conservar alguno de los archivos de la instalación anterior hazles una copia.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Lun 14 Sep 2009 - 19:27

grazias,he descargado el .deb y installado ya.
Código:
Strumento in esecuzione: gcbasic

Great Cow BASIC (0.9 12/8/2009)

Compilando /home/alejandro/Scrivania/Robot/Rover/Firmware/16F88/Control_transmiciòn.gcb ...
Programa compilado exitosamente!

Ensamblando y descargando programa ...

Fatto.

volvamos a la questiòn libreria.soy de acuerdo con las observaciones hechas.por eso he usado una llamada de interrupt fuera de la libreria
Código:
On Interrupt PORTBChange call Interrupt_I2C_Serial
no he usado un llamado con SSP1Ready pues quiero gestir todos los interrupts de las puertos B ( I2C y USART )
Código:
INTCON=b'11001000'
es verdad,la libreria USART nueva no me compila con un quarzo a 20mhz un baud a 600 (me parecia extraṅo).el dilema serà se poner un quarzo de 20 o uno de 4 mhz.
por ahora serà asi el codigo en el modulo de transmiciòn datos(16F88)
Código:
'''''''''' CONFIGURACION DEL PIC '''''''''''''''''
#chip 16f88,4
#config OSC=XT,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
'''''''''''''''''''''''''''''''''''''''
#include                    'libreria I2C slave
'''''''''''''''''''''''''''''''''''''''
#define Slv_Comunicacion b'00111100'            'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
#define USART_BAUD_RATE 600                    'Configuro a 600 baud de transmiciòn

#define USART_BLOCKING
Dim RxBuffer(RxBufferSize) 
'INTCON=b'11001000'  'por ahora no los uso
ADCON1=b'00000000'
DIR PORTA b'00000'                              'Puerto A todos out
DIR PORTB b'00010110'                          'Puerto B 1/2/4 in,los demas out
PORTA=b'00000'                                  'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down

On Interrupt PORTBChange call Interrupt_I2C_Serial

InitSSP                                        'Config. reg. SSP

InitUSART

Sub Interrupt_I2C_Serial                        'Subrutina interrupciones
    if PIR1.SSPIF=1 then
      TestLed=RxBuffer(1)                      'Recibe byte del Master
      HserPrint "Test"

      HserSend TestLed

      HserPrint "#®️"

      wait 10 ms
      Rotate TestLed Right
      PortB.0 = Status.C 
      Rotate TestLed Right
      PortB.3 = Status.C 
      Rotate TestLed Right
      PortB.6 = Status.C 
      Rotate TestLed Right
      PortB.7 = Status.C
      PIR1.SSPIF=0                            'Flag de interrupt bajo
      SSPCON.CKP=1                            'Deja la linea SCL del bus I2C libre
    end if
End Sub

Do
'''''''''''
Loop
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Sáb 19 Sep 2009 - 19:26

dame un ultimo consejo,pikitin,antes de programar el microchip master.puedes controlar este codigo para escribir en una memoria 24LC256:
Código:
SUB I2C_Master_to_Memory_256(IDAddress,MemAddress,Dato)
    Start                                        '
    TxI2C(IDAddress)                              'Device ID Slave
    TxI2C(MemAddress_H)                          'Device high Address memory
    TxI2C(MemAddress)                            'Device low Address memory
    TxI2C(Dato_H)                                'Send high byte data
    TxI2C(MemAddress_H+1)                        'Device high Address memory 
    TxI2C(MemAddress+1)                          'Device low Address memory
    TxI2C(Dato)                                  'Send low byte data
    WAIT 25 ms                                    '
    Stop                                          '
END SUB
mi problema es como se dice a GCBasic que un valor es el highbyte o un lowhigh.como vez usè la dicciòn del mikrobasic.es lo mismo para GCBasic??
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Sáb 19 Sep 2009 - 20:34

Si... creo que así vale, lo único es que deberías definir la función así:

SUB I2C_Master_to_Memory_256(IDAddress as word, MemAddress ,Dato as word) #NR

Pero la función o subrutina TxI2C() debe aceptar solo datos de tipo byte, supongo que será así.

Lo de #NR es para ahorrar algunas lineas de código, solo es para que el compilador sepa que los argumentos no se ván a cambiar.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Sáb 19 Sep 2009 - 21:22

ok,termino de montar el circuito y paso a los test de comunicaciòn.te hago saber,vale??
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Vie 9 Oct 2009 - 10:39

he construido el circuito 2 semanas atràs.
si uso este codigo con el 16F767 y una Eeprom 24C64 o una 24C256 funciona:
Código:

''''''''''''''' CONFIGURACION DEL PIC '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#chip 16F767, 20                                  'modelo de pic y velocidad de reloj
#config CP_OFF,DEBUG_OFF,WDT_OFF,PWRTE_ON,VBOR_2_7,BOREN_0,MCLR_ON,OSC=HS,IESO_OFF,FCMEN_OFF
#include <MasterI2C.h>
''''''''''''''' SETUP MASTER I2C '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
#define ClockValue b'00010000'                    'ClockValue o SSPADD = (FOSC / (4 * Baud)) - 1  ---  16 = 312500 HZ
''''''''''''''' VARIABLES '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM Index_Byte,Address_mem,vValor AS BYTE
DIM Slv_Motores_Wr,Slv_Motores_Rd AS BYTE
DIM Slv_Comunicacion_Wr,Slv_Comunicacion_Rd AS BYTE
DIM Slv_Mem_Wr,Slv_Mem_Rd AS BYTE
''''''''''''''' SUB PROCEDURAS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SUB I2C_Master_to_Memory(MemAddress,Dato)#NR
    Start                                        'Start I2C
    TxI2C(Slv_Mem_Wr)                            'Device ID Slave
    TxI2C(MemAddress_H)                          'Device high Address memory
    TxI2C(MemAddress)                            'Device low Address memory
    TxI2C(Dato)                                  'Send low byte data
    Stop                                          'Stop I2C
END SUB

SUB I2C_Master_to_Slave(IDAddress,Dato)#NR
    Start                                        'Start I2C
    TxI2C(IDAddress)                              'Device ID write byte
    TxI2C(Dato)                                  'Send byte size data
    Stop                                          'Stop I2C 
END SUB 
''''''''''''''' PARAMETROS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
INTCON=b'00000000'
ADCON1=b'10001111'
TRISA=b'000000'                                  'Puerto A todos out
TRISB=b'00000000'                                'Puerto B todos out
TRISC=b'00011000'                                'Puerto B 3/4 in,los demas out
PORTA=b'00000'                                    'Puerto A todos down
PORTB=b'00000000'                                'Puerto B todos down
PORTC=b'00000000'                                'Puerto C todos down
Address_mem=0                                    'Inicializo la variable del Address
vValor=0                                          'Inicializo la variable del dato
Slv_Comunicacion_Wr=0xA2                          'b'10100010'
Slv_Comunicacion_Rd=0xA3                          'b'10100011'
Slv_Motores_Wr=0xA4                              'b'10100100'
Slv_Motores_Rd=0xA5                              'b'10100101'
Slv_Mem_Wr=0xA6                                  'b'10100110'
Slv_Mem_Rd=0xA7                                  'b'10100111'
''''''''''''''' INICIA ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
InitI2C 
WAIT 500 ms                                      'Inicia la comunicacion                               
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DO
  I2C_Master_to_Memory(Address_mem,vValor)      'Envia dato a la memoria
  Address_mem=Address_mem+1                      'Incrementa Address_mem de 1
  vValor=vValor+1                                'Incrementa vValor de 1
LOOP UNTIL Address_mem=0xFF
''''''''''''''' TERMINA '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
END
escribe en la Eeprom perfectamente.

màs si cambio el codigo para conversar con el slave:
Código:

DO
  I2C_Master_to_Slave(Slv_Comunicacion_Wr,vValor) 'Envia dato al slave,esperemos.....
  vValor=vValor+1                                'Incrementa vValor de 1
  WAIT 20 ms                                      'Espera escritura
LOOP UNTIL Address_mem=0xFF
''''''''''''''' TERMINA '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

este es el codigo en el slave:
Código:


'''''''''''''''''''''''''''''''''''''' CONFIGURACION DEL PIC ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#chip 16f88,4
#config OSC=XT,WDT_OFF,PWRTE_ON,MCLR_ON,CP_OFF
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#include <SSP_I2C_PicSlave.h>                  'libreria I2C slave
''''''''''''''' SETUP SLAVE I2C '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define PicSlave 0xA2                          'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos byte en recepciòn para activar el interrupt
''''''''''''''' VARIABLES '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM RxBuffer(RxBufferSize) 
DIM Address_Eeprom AS BYTE
''''''''''''''' SUB PROCEDURAS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub I2C_Interrupt                              'Subrutina interrupciones I2C
    EPWrite(Address_Eeprom,RxBuffer(1))        'Recibe byte del Master y lo escribe en la Eeprom del microchip
    Address_Eeprom=Address_Eeprom+1
    WAIT 5 ms
End Sub
''''''''''''''' PARAMETROS ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TRISA=b'00000'                                  'Puerto A todos out
TRISB=b'00010010'                              'Puerto B 1 y 4 in,los demas out
PORTA=b'00000'                                  'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
Address_Eeprom=0
'''''''''''''' INICIA '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Interrupt SSP1Ready call I2C_Interrupt      'Se hay un envio del Master
InitSSP                                        'Configuracion registros SSP y activar el interrupt 
WHILE True
  '''''''''''''''''''''''''''''''''''''''
WEND
sinceramente he ido al sitio de GCBasic,màs tengo problemas al postar el codigo.aparte el mio ingles.
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Vie 9 Oct 2009 - 10:43

me olvidava.tambien usando el mikrobasic(la prueva del nueve,mas quisiera hacer todo el codigo en GCBasic) tengo el mismo problema.solo que algunos caracteres son escritos en modo casual.
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Sáb 10 Oct 2009 - 20:45

Que tal alejandro?

Mira... yo no conozco el I2C, pero por lo que veo en la librería ( SSP_I2C_PicSlave.h ) no tienes que hacer nada con las interrupciones, entonces he añadido una linea a SS_I2C_PicSlave.h para que "avise" cuando recive dato ( I2C_rec_flag ).
También he cambiado la forma como configura las interrupciones por lo que te comenté en anteriores mensajes.

Esta es la nueva versión:
Código:


'***************************************************************
'This library is for the use of a Pic device as an I2C Slave
'thru the Synchronous Slave Port (SSP). This is a port of the
'Microchip AN734a to GCBasic.
'By Kent Schafer August 16,2007 - Modified October 10, 2009
'
'Pic is a tm of Microchip, I2C is a tm of Phillips/NXP
'***************************************************************

Dim I2C_rec_flag as bit        'data received flag

Sub InitSSP
    SSPCON = 0x36 'set for 7 bit address
    SSPADD = PicSlave 'I2C address of slave

    #script 'GCBasic treats AnyArray(1) as variable
        RxBufferSize = BufferLen
        if BufferLen = 1 then RxBufferSize = 2
    #endscript
   
    On Interrupt SSP1Ready call SlaveStatus 'Setup Interrupt
End Sub

Sub SlaveStatus
    SSPSTATtemp = SSPSTAT AND b'00101101'

    Select Case SSPSTATtemp
        'Case #1 Write operation, last byte was an address, buffer full
        Case b'00001001'
            For index = 1 to BufferLen
                RxBuffer(index) = 0
            Next
            DummyRead = SSPBUF 'Dummy read of SSBUF

        'Case #2 Write operation, last byte was data, buffer full
        Case b'00101001'
            For index = 1 to BufferLen
                RxBuffer(index) = SSPBUF
            Next
            Set I2C_rec_flag on

        'Case #3 Read Operation, last bytes was an address, buffer is empty
        Case b'00001100'
            index = 1
            BufferTemp = RxBuffer(index)
            WriteI2C BufferTemp

        'Case #4 Read operation, last byte was data, buffer is empty
        Case b'00101100'
            For index = 2 to BufferLen
                BufferTemp = RxBuffer(index)
                WriteI2C BufferTemp
            Next

        'Case #5 A Nack was received when transmitting data from master
        Case b'00101000'
        'Set ERROR On
    End Select
End Sub


Sub WriteI2C(BufferTemp)#NR
    Do: Loop While BF = 1          'Is buffer full?
    Do
        WCOL = 0                    'Clear the collision flag
        SSPBUF = BufferTemp
    While WCOL = 1                  'Was there a collision?
    CKP = 1                        'Release clock
End sub



Y este ejemplo de uso (modificando tu programa):

Código:


'''CONFIGURACION DEL PIC
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#chip 16f88,4
#config OSC = HS, WDT_OFF, PWRTE_ON, MCLR_ON, CP_OFF

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#include <SSP_I2C_PicSlave.h>                    'libreria I2C slave

'SETUP SLAVE I2C ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define PicSlave 0xA2                          'Configuro Pic_Slave I2C_address
#define BufferLen 1                            'Cuantos bytes se

''VARIABLES'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DIM RxBuffer(RxBufferSize) 
DIM Address_Eeprom AS BYTE

''SUB PROCEDURAS '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub I2C_Received                                'Subrutina recibido I2C
    EPWrite(Address_Eeprom,RxBuffer(1))        'Recibe byte del Master y lo escribe en la Eeprom
    Address_Eeprom=Address_Eeprom+1
End Sub

''PARAMETROS'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TRISA=b'00000'                                  'Puerto A todos out
TRISB=b'00010010'                              'Puerto B 1 y 4 in,los demas out
PORTA=b'00000'                                  'Puerto A todos down
PORTB=b'00000000'                              'Puerto B todos down
Address_Eeprom = 0

'INICIA'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
InitSSP                                        'Configuracion SSP y activar el interrupt 

Do
    If I2C_rec_flag on then call I2C_Received          'Si ha recibido byte llama a sub
Loop

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Sáb 10 Oct 2009 - 21:15

no mal como idea.
mas antes de modificar la libreria(ya he hecho una modifica en la libreria para el master y ahora "escribe" bien en las memorias esternas.antes no funcionaba) lo hare en el codigo esterno.
la modifica de la libreria MasterI2C.h es esta para el 16F767:
Código:

sub InitI2C 'Disable slew rate control (SMP)
  SSPSTAT = b'11000000'            'ClockValue or SSPADD = (FOSC / (4 * Baud)) - 1  -----  original es b'10000000'
  SSPADD = ClockValue 'Clear the register, only cleared on POR
  SSPCON2 = 0 'Set SSPEN and SSPMx bits for SSP Enable and Master I2C mode
  SSPCON = b'00111000'              'original es b'00101000'
  SET PIR1.SSPIF OFF
  SET PIR2.BCLIF OFF 
end sub
mañana hago las pruevas.
esperemos bien........ prueva con usart.h y masterI2C.h Icon_cool
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Dom 11 Oct 2009 - 15:21

nada........... prueva con usart.h y masterI2C.h Icon_sad
no quiere saber nada.en cambio con la Eeprom funciona.
hare un test del circuito.
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Jue 15 Oct 2009 - 18:10

la situaciòn es esta.
en los pin SDA y SCL de los slave y memoria 24C64/24C256 saldadas resistencias de 270 Ohm para "cortar perturbaciones" en la linea I2C.
continua a "escribir" en las memorias perfectamente.mas los slave no quieren saber de escribir en las memorias internas.a este punto tengo dudas si los datos llegan o el interrupt funciona.en la procedura interrupt pongo solo un test con led.
Código:

Sub I2C_Interrupt                             
    IF SET PORTB.7 OFF THEN SET PORTB.7 ON
    IF SET PORTB.7 ON THEN SET PORTB.7 OFF
End Sub
veamos si funciona.................
Puede ser que los micros slave funcionen solo a 100KHZ y que tenga que cambiar las resistencias de pull-up de 2K2 con las resistencias de 10K??????
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Pikitin Vie 16 Oct 2009 - 3:28

Solo un detalle:

Código:
IF PORTB.7 OFF THEN SET PORTB.7 ON
No vale: IF SET..

No sé muy bién como funciona I2C, entonces a ver si preguntando me entero:

¿los datos los mandas con otro pic?
¿para enviar cada dato envias: I2Caddress+dato?... I2Caddress creo que esto es para comunicar con varios slaves.. no?

En el cado de escribir a una eeprom externa, ¿tienes que mandar I2Caddress+direccion(memoria)+dato ?


Saludos.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Vie 16 Oct 2009 - 10:31

No vale: IF SET..
gracias,hare las correcciones necesarias.

¿los datos los mandas con otro pic?
si,el master envia o pide informaciòn a los slave y a la memoria de sistema.
el bus es compuesto de:
1 master 16F767 (control sensores,accionamiento de los motores,ruta,calculo de la misma,pedido al chip de comunicaciòn de enviar a traves del modulo radio los datos al PC,etc...)
1 slave 16F876A para control de los motores(PID+odometro+control de consumo de corriente,etc...) --> ID_Address=0xA4
1 slave 16F88(gestiòn de la comunicaciòn en entrada y salida de datos para y del PC) --> ID_Address=0xA2
1 memoria 24C256(la caja negra del rover) --> ID_Address=0xA6

¿para enviar cada dato envias: I2Caddress+dato?... I2Caddress creo que esto es para comunicar con varios slaves.. no?
si, la comunicaciòn entre chip(master <--> slave) es:
inicio de la comunicaciòn I2C --> envio ID_Address --> envio dato o pedido de datos al slave.
el ID_Address en los micros se establece a nivel software.
en las memorias con la conexiòn o menos al Vcc(+5V).
ejemplo:
pin1 + pin2 al Vcc -- pin 3 al GND
en binario:
1010 -- fijos,son el head
0 -- pin 3 al GND=0
1 -- pin 2 al Vcc=1
1 -- pin 1 al Vcc=1
x -- bit de escritura/lectura.si es =1 entonces el ID_Address avisa que a ese dispositivo el master pedira una informaciòn.si es =0 avisa que el master pedira una escritura sobre el dispositivo
1010 0 11 0 =166=0xA6(en escritura.bit 0=0)
1010 0 11 1 =167=0xA7(en lectura.bit 0=0)
En el cado de escribir a una eeprom externa, ¿tienes que mandar I2Caddress+direccion(memoria)+dato ?
depende de la memoria.las memorias hasta el valor 24C16 es asi.
en cambio las memorias desde la 24C32 en adelante se deve enviar:
ID_Address de la memoria
High_byte del Address(direcciòn de la memoria a donde va a parar el dato)
Low_byte del Address(direcciòn de la memoria a donde va a parar el dato)
Dato
Código:

SUB I2C_Master_to_Memory(MemAddress,Dato)#NR
    Start                                                'Start I2C
    TxI2C(Slv_Mem_Wr)                            'Device ID Slave
    TxI2C(MemAddress_H)                          'Device high Address memory
    TxI2C(MemAddress)                            'Device low Address memory
    TxI2C(Dato)                                      'Send low byte data
    Stop                                                'Stop I2C
END SUB


SUB I2C_Master_to_Slave(IDAddress,Dato)#NR
    Start                                        'Start I2C
    TxI2C(IDAddress)                              'Device ID write byte
    TxI2C(Dato)                                  'Send byte size data
    Stop                                          'Stop I2C 
END SUB 
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por alejandro Mar 17 Nov 2009 - 18:24

de nuevo acà.estube parado con el projecto por culpa de los motores nuevos.tube que cambiar el esquema.ahora funcionan muy bien.este es el nuevo esquema.los terminales Enable_X son conectados a pin1(Enable_1) y pin9(Enable_2) del L293B(down=habilitado - low=deshabilitado).
PWM_X_A y PWM_X_B son los carrier de PWM que llegan del inverter SN74HC04,que a su vez son generados de los CCP1 y CCP2 del 16F876A.

prueva con usart.h y masterI2C.h L293b

y este es el codigo de test
Código:

'*  Name    : Programa_test en gcbasic para 16F876A             
'*  Author  : Alejandro Daniel Indulgenza                                   
'*  Notice  : Copyright (c) 2009                                                       
'*  Code    : free code                                                                         
'*  Date    : 18/11/2009                                                                   
'*  Version : 1.0                                                                               
'****************** CONFIGURO EL PIC **********************************************
#chip 16F876A,20
#config OSC=HS,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,BODEN_OFF,CPD_OFF,LVP_OFF
'****************** MOTORES *****************************************************
SUB Motores_Stop()
    HPWM 1,10,127
    HPWM 2,10,127
END SUB

SUB Motores_Adelante()
    HPWM 1,10,0
    HPWM 2,10,0
END SUB

SUB Motores_Adelante_Lento()
    HPWM 1,10,63
    HPWM 2,10,63
END SUB

SUB Motores_Atras()
    HPWM 1,10,255
    HPWM 2,10,255
END SUB

SUB Motores_Atras_Lento()
    HPWM 1,10,191
    HPWM 2,10,191
END SUB

SUB Motores_90_DX()
    HPWM 1,10,255
    HPWM 2,10,0
END SUB

SUB Motores_90_SX()
    HPWM 1,10,0
    HPWM 2,10,255
END SUB

SUB Motores_DX()
    HPWM 1,10,127
    HPWM 2,10,0
END SUB

SUB Motores_SX()
    HPWM 1,10,0
    HPWM 2,10,127
END SUB
 '****************** CONFIGURO LAS PUERTAS *********************************************
INTCON=0                                      'Interrupt desabilitados
ADCON1=130                                '10000010 -- Cinco puertas analogicas
TRISA=47                                        'PORTA como output
TRISB=0                                          'PORTB como output
TRISC=0                                          'PORTC como output
PORTA=0                                        'Setaje PORTA
PORTB=6                                        'Setaje PORTB.Activo Enable_1 + Enable_2
PORTC=6                                        'Setaje PORTC
'****************** ESPERO Y PARTO ***************************************************
PWMOn
Motores_Stop()
WAIT 2  s
'****************** INICIA EL CICLO ***************************************************
FOR Ciclo=1 TO 3
        Motores_Adelante_Lento()
        WAIT 4  s
        Motores_Adelante()
        WAIT 4  s
        Motores_Adelante_Lento()
        WAIT 4  s
        Motores_Stop()
        WAIT 1  s
        Motores_Atras_Lento()
        WAIT 4  s
        Motores_Atras()
        WAIT 4  s
        Motores_Stop()
        WAIT 1  s
        Motores_90_DX()
        WAIT 4  s
        Motores_Stop()
        WAIT 1  s
        Motores_90_SX()
        WAIT 4  s
        Motores_Stop()
        WAIT 1  s
        Motores_DX()
        WAIT 4  s
        Motores_Stop()
        WAIT 1  s
        Motores_SX()
        WAIT 4  s
        Motores_Stop()
        WAIT 2  s
NEXT
PWMOff
PORTB=0                                            'Disactivo Enable_A y Enable_B del L293B
alejandro
alejandro
Participante Activo
Participante Activo

Mensajes : 87
Fecha de inscripción : 12/02/2009

Volver arriba Ir abajo

prueva con usart.h y masterI2C.h Empty Re: prueva con usart.h y masterI2C.h

Mensaje por Contenido patrocinado


Contenido patrocinado


Volver arriba Ir abajo

Página 1 de 2. 1, 2  Siguiente

Volver arriba

- Temas similares

 
Permisos de este foro:
No puedes responder a temas en este foro.